Greetings!
I've some working code that I'm hoping to streamline. I'm open to varying interpretations of better algorithms that accomplish the same task. Here is the code that encrypts/decrypts:
...I've attached the source, a sample text and compiled version with PB/CC 4 if you'd like to download that instead. Much thanks.
I've some working code that I'm hoping to streamline. I'm open to varying interpretations of better algorithms that accomplish the same task. Here is the code that encrypts/decrypts:
Code:
#COMPILE EXE #DIM ALL DEFDWD A - Z DECLARE SUB Encrypt (BYVAL TxtFileName AS STRING) FUNCTION PBMAIN() Encrypt "aeotp10.txt" END FUNCTION 'For encryption/decryption you basically just need to XOR the bytes with the correct key. '1. Copy first 12 bytes. '2. XOR next 12 bytes with this key: ' BYTE hkey[12] = {0xA7, 0x8F, 0x56, 0xFD, 0x3E, 0x1D, 0x7C, 0xBD, 0xDC, 0xE6, 0xBE, 0x6D }; '3. XOR the bytes to the end of the data file with this key: ' BYTE key[35] = { 0x80, 0xDD, 0x13, 0x7F, 0x8C, 0xDA, 0x80, 0xC2, 0xA7, 0x51, 0xEA, 0x21, ' 0x86, 0xA1, 0xAE, 0xF0, 0x1D, 0xB1, 0xFC, 0x1D, 0xA1, 0x55, 0xDC, 0x9C, 0x47, 0x49, 0x80, ' 0x8B, 0xBF, 0x60, 0x65, 0xFD, 0xDA, 0xFD, 0x47 }; SUB Encrypt (BYVAL TxtFileName AS STRING) DIM sFile AS STRING ' For storing File Name to be encrypted/Decrypted DIM lFnum1 AS LONG ' For Source File DIM lFnum2 AS LONG ' For Temprory Destination File DIM lPos AS LONG ' For Iterating through each byte in Source File DIM bData AS BYTE ' For Reading Data from Source File DIM bDataC AS BYTE ' For storing Complemented (or encrypted) bData in Destination File DIM sKey1(12) AS INTEGER ' 0xA7, 0x8F, 0x56, 0xFD, 0x3E, 0x1D, 0x7C, 0xBD, 0xDC, 0xE6, 0xBE, 0x6D DIM sKey2(35) AS INTEGER sKey1(0) = &HA7 sKey1(1) = &H8F sKey1(2) = &H56 sKey1(3) = &HFD sKey1(4) = &H3E sKey1(5) = &H1D sKey1(6) = &H7C sKey1(7) = &HBD sKey1(8) = &HDC sKey1(9) = &HE6 sKey1(10) = &HBE sKey1(11) = &H6D sKey2(0) = &H80 sKey2(1) = &HDD sKey2(2) = &H13 sKey2(3) = &H7F sKey2(4) = &H8C sKey2(5) = &HDA sKey2(6) = &H80 sKey2(7) = &HC2 sKey2(8) = &HA7 sKey2(9) = &H51 sKey2(10) = &HEA sKey2(11) = &H21 sKey2(12) = &H86 sKey2(13) = &HA1 sKey2(14) = &HAE sKey2(15) = &HF0 sKey2(16) = &H1D sKey2(17) = &HB1 sKey2(18) = &HFC sKey2(19) = &H1D sKey2(20) = &HA1 sKey2(21) = &H55 sKey2(22) = &HDC sKey2(23) = &H9C sKey2(24) = &H47 sKey2(25) = &H49 sKey2(26) = &H80 sKey2(27) = &H8B sKey2(28) = &HBF sKey2(29) = &H60 sKey2(30) = &H65 sKey2(31) = &HFD sKey2(32) = &HDA sKey2(33) = &HFD sKey2(34) = &H47 lPos = 1 sFile = TxtFileName lFnum2 = FREEFILE OPEN "tmp" FOR BINARY ACCESS WRITE AS #lFnum2 lFnum1 = FREEFILE OPEN sFile FOR BINARY ACCESS READ AS #lFnum1 DO WHILE NOT EOF(lFnum1) GET #lFnum1, lPos, bData 'Reading Data Byte by Byte from Source File IF NOT EOF(lFnum1) THEN IF lPos <= 12 THEN ' just copy the data bDataC = bData ELSE IF lPos <= 24 THEN 'Encrypt/Decrypt with first key bDataC = bData XOR sKey1(lPos - 12 - 1) ELSE 'Encrypt/Decrypt with second key bDataC = bData XOR sKey2((lPos - 24 - 1) MOD 35) END IF END IF PUT #lFnum2, lPos, bDataC 'Writing Encrypted Data To Temporary Destination File lPos = lPos + 1 END IF LOOP CLOSE #lFnum1 CLOSE #lFnum2 KILL sFile ' Deleting Source File NAME "tmp" AS sFile 'Renaming Temporary Destination File to Real File Name END SUB
Comment