![]() Decryption Code (a) Create the Polybius Table (b) Use input with 's' option to get the message to decrypt from the user ![]() Encryption Code (a) Create the Polybius Table (b) Use input with 's' option to get the secret message from the user (c) For each character in the message, find its location in the Polybius Table (d) Display the encrypted message as Encrypted message: XXXX where XXX is the actual pattern of numbers 2. Also, the cipher will not change any white space it will simply stay the same. The secret message will always be in upper case. m files that perform the encryption and decryption for the Polybius Cipher. The encrypted message will then have two numbers that represent a single letter For example, lets encrypt the following message: ATTACK AT DAWN ATTACK AT DAWN The individual letters from the message correspond to the following numbers: Letter Corresponding Number Putting these numbers together, gives us the following encoded message: 443333446521 4433 23442432 To decode the message, you just do the reverse process! Given two numbers, use the first number as the row and the second as the column in the polybius grid to find the corresponding letter Key steps to solution: For this lab, you will turn in two. , ! Z JM 6 | ? The main idea is to replace letters in your secret message with the corresponding row and column number from the table. This particular cipher depends upon the following secret table, which has the 26 letters from the alphabet along with 10 common punctuation marks, randomly arranged in a 6 by 6 grid: 1 2 3 4 5 6 1 R) VBS 2 KXDWLQ 3 Y NT ? G 4: P (AU. Please check out the numerous online resources if you want more information. Cryptography is a rich subject in its own right, but we will not have time to cover it in detail. Again, as a user I'd much rather be able to take input from a file and/or write output to a file (and this still allows me to run it interactively in the rare circumstance that I really want to).įor implementation of the cipher, I'd consider using a little math instead of the tables you're currently using.Polybius Square Cipher Key programming concepts: if statements, loops, strings The Polybius Square Cipher is a simple encryption technique based on letter substitution (check out ) that will allow us to send Introduction: This assignment will give you a brief introduction into cryptography using the Polybius Square Cipher! Cryptography allows us to encode and decode messages that are difficult to decipher without knowledge of a secret key/table/code. Likewise, each would act as a filter, taking its input from cin, and writing its output to cout (or possibly read/write other files if you specify them on the command line). As a user, I'd much rather type decrypt or encrypt than have to interactively enter an 'e' or 'd' to tell it whether to encrypt or decrypt. I think I'd start by splitting it into two pieces, one to encrypt and one to decrypt. If you expect every character to be upper case, either (1) tell the user (not recommended) or (2) upper case the string yourself: std::transform(input.begin(), input.end(), input.begin(), ::toupper) For example, for(int i = 0 i for std::isspace. Use ranged-based loop instead of index loop. Use auto to simply some variable definitions if you want to: // std::vector coords = getCoords() Don't allocate memory if you don't have too (this might actually not allocate memory for the std::string, due to SSO actually). SquareIJ doesn't have to be a std::string, it can be a simple char. Your choice variable really wants to be an enum instance: enum class mode When compiled with -Wall, your code produces 2 same warnings: warning: comparison between signed and unsigned integer expressions It's not that messy IMO, but there are a few things which you could have done better:Īlways compile code with every warning turned on, and fix them. This code, in my opinion, is quite messy. The getCoords() function gets a string, and then tokenizes the string into a vector of strings, each corresponding to the coordinates of a character.Įxample of "encryption": Encrypt or decrypt = eĮxample of "decryption": Encrypt or decrypt = dĬoordinates (separate with spaces): 12 11 44 The getChoice() function simply gets the e or d character to choose encryption or decryption. As shown in the unordered map and char array, the numbers correspond to the row and column on a 5x5 square: ![]() The Polybius square is a simple way to assign characters numbers, and then "encrypt" and "decrypt" based off of those numbers. Since it is an uncommon cipher, it is nowhere on Code Review.Īlthough the program technically works, it ended up very messy. I attempted to recreate the Polybius square, also called the Polybius checkerboard, which was used in Ancient Greece for cryptography.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |