By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

File input using read()

dfound
P: 52
Hi, I have developed a small encryption program which uses read() function to read an array of size 32768(32kb).After that I would do something like this :

for(long i=0;i<strlen(buf);i++) // buf is array read
buf[i]+=13; //encoding

Well the problem is the code doesn't work on audio and video files.Please help
... :-)
Mar 11 '07 #1
Share this Question
Share on Google+
6 Replies


P: 93
Hi, I have developed a small encryption program which uses read() function to read an array of size 32768(32kb).After that I would do something like this :

for(long i=0;i<strlen(buf);i++) // buf is array read
buf[i]+=13; //encoding

Well the problem is the code doesn't work on audio and video files.Please help
... :-)

What do you mean by "The code doesn't work"? Doesn't it encrypt those files? does it throw a runtime error, or do you simply cannot decode the file and play it back again? If the latterr is the case, please check the value type of the buf array. becasue if u r using a char array, and if the file somewhere had a value like 123, u add 13 to it and u get 136. unrepresentable! This is an error. u should check for whether buf[i] + 13 < 127 before you do buf[i] + 13. This happened to me when I was writing ur same program two months ago.
Mar 11 '07 #2

dfound
P: 52
The Problem Is That It Doesn't Encrypt The Array.after I Encrypt It,the File Still Plays.
Mar 12 '07 #3

sicarie
Expert Mod 2.5K+
P: 4,677
The Problem Is That It Doesn't Encrypt The Array.after I Encrypt It,the File Still Plays.
(just to make sure before moving on to more complicated things) Are you sure you are playing the "encoded" file?
Mar 12 '07 #4

dfound
P: 52
Yes.......
Mar 15 '07 #5

dfound
P: 52
Yes but it does encode other files except audio and video
Mar 15 '07 #6

P: 93
Are u sure u are reading the file in in the binary mode. say.

Expand|Select|Wrap|Line Numbers
  1. ifstream in(filename, ios::in | ios::binary );
  2.  
U should open the file in binary mode.
Mar 15 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.