File input using read()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dfound
    New Member
    • Jan 2007
    • 52

    #1

    File input using read()

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

    for(long i=0;i<strlen(bu f);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
    ... :-)
  • DumRat
    New Member
    • Mar 2007
    • 93

    #2
    Originally posted by dfound
    Hi, I have developed a small encryption program which uses read() function to read an array of size 32768(32kb).Aft er that I would do something like this :

    for(long i=0;i<strlen(bu f);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.

    Comment

    • dfound
      New Member
      • Jan 2007
      • 52

      #3
      The Problem Is That It Doesn't Encrypt The Array.after I Encrypt It,the File Still Plays.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by dfound
        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?

        Comment

        • dfound
          New Member
          • Jan 2007
          • 52

          #5
          Yes.......

          Comment

          • dfound
            New Member
            • Jan 2007
            • 52

            #6
            Yes but it does encode other files except audio and video

            Comment

            • DumRat
              New Member
              • Mar 2007
              • 93

              #7
              Are u sure u are reading the file in in the binary mode. say.

              Code:
              ifstream in(filename, ios::in | ios::binary );
              U should open the file in binary mode.

              Comment

              Working...