Text encryption - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Utilities (https://qb64phoenix.com/forum/forumdisplay.php?fid=8) +---- Thread: Text encryption (/showthread.php?tid=1139) |
Text encryption - AtomicSlaughter - 11-17-2022 Ok, here is a simple program to encode text with a shifting cypher. Usage:- crypt encode 1234 "your data" crypt decode 1234 "encoded data" Code: (Select All) $CONSOLE:ONLY RE: Text encryption - JRace - 11-17-2022 Cool. I've always had a fascination with crypto, although I am certainly no expert. I know just enough about the subject to NEVER trust my own work. Actually, after testing the program below to make sure it worked, I filed it away and it's been my shameful little secret for years, so YOU, dear reader, are among the only people in the world, besides me, who know about this program. This was written, as a proof-of-concept, for GWBasic back in the bronze age. It uses a combination of substitution (by adding a "random" number to each byte), and transposition (rearrangement of bytes). Due to the repeatable nature of the linear congruential random number generator used by GWB (and QB and QB64PE), the sequence of "random" numbers used for encryption may be easily recreated for decryption. The program asks for the name of an Input File (which is the file you want to encrypt or decrypt), an Output File (which will contain the encrypted or decrypted data), and a Key (which will be used as the "seed" for Basic's built-in pseudo-random number generator). WARNING: Be careful with your filename typing; this program does not ask for confirmation if a file with your Output name already exists! Code: (Select All) 5 'File Security Series, Part 1. The code above is unchanged except for the added blank lines to break things into functional blocks. I've always written somewhat "dense" code, ESPECIALLY in olden times. This is what I've always called a "kid brother" cipher, due to it's reliance on a linear congruential generator. LCGs are fast, but simple, and NOT cryptographically secure. This might protect your teenage poetry and sappy love letters from your snot-nosed little sibling, but it WILL NOT stop a knowledgeable code breaker. Lightly tested under QB64PE. Compiles & seems to run fine. Just posting it here in case anyone wants to tinker with it. (My few simple tests seem to indicate that you can ignore the comments in lines 6 & 7 if compiling with QB64PE.) (For any would-be employers reading this, my coding style and level of sophistication have greatly improved in the years since this program was written.) RE: Text encryption - mnrvovrfc - 11-17-2022 (11-17-2022, 07:59 PM)JRace Wrote: Cool. I've always had a fascination with crypto, although I am certainly no expert. I know just enough about the subject to NEVER trust my own work. Actually, after testing the program below to make sure it worked, I filed it away and it's been my shameful little secret for years, so YOU, dear reader, are among the only people in the world, besides me, who know about this program.Thank you for this program. I made the modification for output file existence, refusing to do anything in that case. But it's what I chose to do. Must be tested: run this program a few times to ensure the decrypt/encrypt goes down as expected on the same data set. Then run a program which employs "RANDOMIZE TIMER", run it (hopefully it would be a short time). After that, load this program again and test the decrypt/encrypt like before. It might be easy to emulate eg. the Timex Sinclair random number generator (I read somewhere it just stores 64KB jumbled-up numbers and always refers to that table) but trying to do it for a 16-bit software interpreter and ancient Intel-based processors is harder. That said, an antidote is to place "RANDOMIZE" statement alone as one of the first lines in the code, then involve the integer that must be input to start, into the encryption. RE: Text encryption - bplus - 11-17-2022 This reminds me I need to update my own encryption code for spaces and punctuation... RE: Text encryption - JRace - 11-17-2022 Quote:@mnrvovrfc : I made the modification for output file existence, refusing to do anything in that case. But it's what I chose to do. That's the way I usually do it in programs I write for myself: if the program finds an error, it reports the error then aborts. Quote:@bplus : This reminds me I need to update my own encryption code for spaces and punctuation... Spaces? Those were optional in TRS-80 Basic and I usually opted out, to conserve memory & diskette space. Also, interpreted Basic programs were a couple percentage points faster without extra spaces. I found the requirement for spaces to be quite annoying when I first took up GWBasic. RE: Text encryption - bplus - 11-17-2022 @JRace, I think you misunderstand, I mean encrypt spaces and punctuation along with letters and digits, so word lengths or formats don't give away the contents of the message. RE: Text encryption - SpriggsySpriggs - 11-17-2022 If I can figure out the API for Windows cryptography, I will post something here for that. RE: Text encryption - JRace - 11-17-2022 @bplus : Quote:I think you misunderstand, I mean encrypt spaces and punctuation along with letters and digits, so word lengths or formats don't give away the contents of the message. Aha. Yeah, you don't want to give the Bad Guys any freebies for their decryption efforts. RE: Text encryption - Jack - 11-17-2022 I am like JRace, I don't know anything about encryption but I translated some public domain C code for blowfish encryption, posted it at the extinct forum https://qb64forum.alephc.xyz/index.php?topic=4270.0 |