question about encoding/decoding a text file
Posted: Mon Mar 01, 2021 12:31 pm
hello.
today i didn't find something interesting to code... then i looked into PB help docs and found out about "ciphers" lib in PB so i used the example in AES-ENCODER to write this simple code that runs on console... you enter a sentence and the code encrypt and decrypt it with AES - i was wondering if it would be possible to code a program that reads a whole text file content and then encrypt it and overwrite it back to that text file making it completely encrypted then with same program you can do the opposite and read the whole encrypted text file and decrypt it and overwrite it with the decrypted text? i don't know who to read/write text files yet in FB and i'm sure someone has already written a program that does what i just described...
anyway here is my little code demo:
today i didn't find something interesting to code... then i looked into PB help docs and found out about "ciphers" lib in PB so i used the example in AES-ENCODER to write this simple code that runs on console... you enter a sentence and the code encrypt and decrypt it with AES - i was wondering if it would be possible to code a program that reads a whole text file content and then encrypt it and overwrite it back to that text file making it completely encrypted then with same program you can do the opposite and read the whole encrypted text file and decrypt it and overwrite it with the decrypted text? i don't know who to read/write text files yet in FB and i'm sure someone has already written a program that does what i just described...
anyway here is my little code demo:
Code: Select all
Define.s plain_text, code
Procedure aes_encoder(plain_text.s)
StringMemorySize = StringByteLength(plain_text) + SizeOf(Character) ; Space for the string and its null terminating character
*CipheredString = AllocateMemory(StringMemorySize)
*DecipheredString = AllocateMemory(StringMemorySize)
If AESEncoder(@plain_text, *CipheredString, StringByteLength(plain_text), ?Key, 128, ?InitializationVector)
Print("Ciphered: "+PeekS(*CipheredString)) ; warning, it will stop on the first null byte, only for demo purpose
AESDecoder(*CipheredString, *DecipheredString, StringByteLength(plain_text), ?Key, 128, ?InitializationVector)
Print("Deciphered: "+PeekS(*DecipheredString))
EndIf
DataSection
Key:
Data.b $06, $a9, $21, $40, $36, $b8, $a1, $5b, $51, $2e, $03, $d5, $34, $12, $00, $06
InitializationVector:
Data.b $3d, $af, $ba, $42, $9d, $9e, $b4, $30, $b4, $22, $da, $80, $2c, $9f, $ac, $41
EndDataSection
EndProcedure
OpenConsole()
Print("please enter text to be encoded: ")
plain_text = Input()
aes_encoder(plain_text)
Input()
CloseConsole()