Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Encrypt/Decrypting Files (CR & LF chars not correct in .exes)

Encrypt/Decrypting Files (CR & LF chars not correct in .exes)

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    daniel madden
    wrote on last edited by
    #1

    Hi folks, I am writting a program that Encrypts/Decrypts files (using CFile). It works fine when I do Text files, but when I do an .exe (Decrypting), it puts a different char?? could this have to do with the way I'm reading in the File (mode)? I have tried using it in Binary Mode and still the same! NOTE: All of the characters (placement) are correct, its just that in the .exe there is NOT all of the little rectangular chars...its empty (visually) space (see below). =========================================================== MZÿÿ¸@躴 Í!¸LÍ!This program cannot be run in DOS mode. =========================================================== Here is some code: // Open the file to be read if( cfEnFile.Open( LPCTSTR(csFileName), CFile::modeReadWrite | CFile::typeBinary, &e ) ) { // Get the length of the file DWORD dwSize = cfEnFile.GetLength(); cfEnFile.SeekToBegin(); // fill the buffer with the information from file UINT nBytesRead = cfEnFile.Read( szBufRead, (UINT)dwSize); //(UINT) dwSize ); ... ... ... for (int n=0; n<(int)nBytesRead; n++) { CString csEnByte = szBufRead[n]; m_AESCrypt.TransformString(csRegUPPRead, csEnByte); csBufBytes += csEnByte; } sprintf(szBufWrite, "%s", csBufBytes); cfEnFile.SeekToBegin(); // Write the buffer to the file cfEnFile.Write( szBufWrite, (UINT)dwSize); } Is there anyone who can help!!!!! Thanks in advance! Dan

    C 1 Reply Last reply
    0
    • D daniel madden

      Hi folks, I am writting a program that Encrypts/Decrypts files (using CFile). It works fine when I do Text files, but when I do an .exe (Decrypting), it puts a different char?? could this have to do with the way I'm reading in the File (mode)? I have tried using it in Binary Mode and still the same! NOTE: All of the characters (placement) are correct, its just that in the .exe there is NOT all of the little rectangular chars...its empty (visually) space (see below). =========================================================== MZÿÿ¸@躴 Í!¸LÍ!This program cannot be run in DOS mode. =========================================================== Here is some code: // Open the file to be read if( cfEnFile.Open( LPCTSTR(csFileName), CFile::modeReadWrite | CFile::typeBinary, &e ) ) { // Get the length of the file DWORD dwSize = cfEnFile.GetLength(); cfEnFile.SeekToBegin(); // fill the buffer with the information from file UINT nBytesRead = cfEnFile.Read( szBufRead, (UINT)dwSize); //(UINT) dwSize ); ... ... ... for (int n=0; n<(int)nBytesRead; n++) { CString csEnByte = szBufRead[n]; m_AESCrypt.TransformString(csRegUPPRead, csEnByte); csBufBytes += csEnByte; } sprintf(szBufWrite, "%s", csBufBytes); cfEnFile.SeekToBegin(); // Write the buffer to the file cfEnFile.Write( szBufWrite, (UINT)dwSize); } Is there anyone who can help!!!!! Thanks in advance! Dan

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Since you indicate that it works with TEXT files but not EXE files, likely there is a 7 bit character dependancy within your code. However I can not see that from the code that you have posted. Possibly something within the 'TransformString' method is not dealing with the 8th bit correctly. HTH.

      U 1 Reply Last reply
      0
      • C Chris Meech

        Since you indicate that it works with TEXT files but not EXE files, likely there is a 7 bit character dependancy within your code. However I can not see that from the code that you have posted. Possibly something within the 'TransformString' method is not dealing with the 8th bit correctly. HTH.

        U Offline
        U Offline
        User 749
        wrote on last edited by
        #3

        Hey Dan, Not to burst your bubble or anything, but posting an encryption hash algorithm with full commenting to the Web is not going to make your program very secure. (Or I suppose you trust us fellow programmers!) Anyway, I suppose it won't hurt, since this cryptography scheme is already published in "Applied Cryptography." Brian Hart

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups