Simple encryption and decryption program in c


















But before going through the program of encryption and decryption, let's first understand about what it actually means when encrypting or decrypting a file. Data encryption means converting the original data into a form or code that can not be read or understand by any people public. Because encrypted data can only be accessed by authorized person. Here authorized person means, a man who knows its decryption key formula or password.

Decryption key is a password or formula that is used to convert the cyphertext to plaintext or original text. Note - Encrypted data is known as cyphertext, whereas unencrypted data is known as plaintext. Encrypting a file means, we will convert the plaintext original content of file to cyphertext. So that our credential information stored in a file gets converted into cyphertext.

Whereas decrypting a file means, getting our content back to original form. Here are the things that must have to do, before going through the program given below. Because, we have created a program to encrypt a file and then created another program to decrypt the same file.

Then we must have to create a file in the same directory where program's source code is going to be saved. For example, create a folder named c programs to the parent directory named Documents.

And create a file named codescracker. Some are quite unclear. For instance: UString , Rid , Sid , raw , those are very vague names. Try to name things in a way to not leave margin for misinterpretation. UString should probably be unencryptedPassword , then you could symmetrically rename Password to encryptedPassword. Rid is a bad abbreviation for the passwordId.

I'm not exactly sure what int raw is representing Your naming convention for methods is not uniform. You have most of them with PascalCase , but menu and about break that pattern. PEND is another unnecessary abbreviation, in my view. You should be explicit and name it PasswordEncryption. This feels like a code smell :. If you you are not comfortable with using the punctuation characters for these operators, then you can use the standard name aliases or , and , not , etc You don't have to define your own ones.

Though I would suggest that you don't use them and stick to the standard way of writing logic ops using the punctuation characters. The wordy operators are not very popular and rarely found in any production code. But this is an open-ended discussion anyway. Your code is filled with magic numbers. Taking the constructor of PEND , for instance, there are five or six different constants used, none of these are explained with comments.

Try to turn them into named constants, or at least comment why you've chosen the given values. Aren't you getting a memory access violation when running this code?

Instead os using raw arrays, consider std::array or std::vector , using the size method to query the array length. Finally, some spacing between arithmetical operators and expressions tends to improve code readability.

For the same reasons as above, raw can be removed from being a member variable and used as a function local variable. For the same reasons as above, UString can be removed from being a member variable and used as a function local variable. I don't see the need for Rid as a member variable either. While you can't quite make it unbreakable, you can make it ridiculously hard to brute-force by using multiple keys in a pattern like so:. It doesn't look that much more secure, but the reason for using multiple keys rather than just one, is that for each additional key you use, you effectively double the amount of time it takes to brute force the encrypted string.

Full source in a variety of languages available on GitHub. Blog Contact. Hey, if you didn't already know, I'm currently working on an open world stealth exploration game called Farewell North in my spare time, which is available to wishlist on Steam!



0コメント

  • 1000 / 1000