Answered step by step
Verified Expert Solution
Question
1 Approved Answer
code in c++ #ifndef PROJ05_PLAYFAIR #define PROJ05_PLAYFAIR #include using std::string; #include // playfair from // http://practicalcryptography.com/ciphers/classical-era/playfair/ const string alphabet_minus_j = abcdefghiklmnopqrstuvwxyz; const int dim =
code in c++
#ifndef PROJ05_PLAYFAIR #define PROJ05_PLAYFAIR #includeDescription Most cyphers, like a Caesar cypher or a Rot13 cypher, are substitution cyphers. In a substitution cypher one substitutes one letter for another using some simple algorithm. For example, here is a Rot13 cypher (a right rotation of the alphabet by 13) Original: abce fgh ijklmnopqrstu vwx yz Encoding: n o p g r s t u v w x y z a b c e fahijkm To generate a secret message, you substitute the original letter with its associated encoding: ello tqxxa To decode, you just do the reverse. Simple eh? Yes, and easy to break. Substitution cyphers are very vulnerable to statistical measures. We know the frequency of letter usage in English (in any language) and, if we have enough text, we can figure out the encoding using those statistics. See https://en.wikipedia.org/wiki/Letter frequen How to get around this vulnerability? Well, there are many approaches but one, relatively simple, approach is to encode more than just single letters. What if we encode every pair of letters and substitute one pair for another? This is a digraph cypher, so called because pairs of letters are called digrams (also called bigrams). It was first used in the 1850's and called the Playfair cypher https://en.wikipedia.org/wiki/Playfair ciphe Why would this be any better? Well, now you have a much bigger set that you have to break. Instead of 26 substitutions, you have 26x26 substitutions (676) to find. Though digram/bigram frequency is available, the process is more difficult. We could do trigrams, quadgram, quintgrams even! http://practicalcryptography.com/cryptanalysis/letter- frequencies-various-languages/english-letter-frequencies/ but we'll stick with digrams The Playfair Algorithm Plaintext Preparation We prepare the plaintext, the string we are going to encode, as follows. we will only represent the characters a-z (minus 'j', which is not represented). Any capitalized letters are converted to lower case, Any other character is removed from the plaintext. Thus numbers, spaces, punctuation and the letter j' and 'J' are Description Most cyphers, like a Caesar cypher or a Rot13 cypher, are substitution cyphers. In a substitution cypher one substitutes one letter for another using some simple algorithm. For example, here is a Rot13 cypher (a right rotation of the alphabet by 13) Original: abce fgh ijklmnopqrstu vwx yz Encoding: n o p g r s t u v w x y z a b c e fahijkm To generate a secret message, you substitute the original letter with its associated encoding: ello tqxxa To decode, you just do the reverse. Simple eh? Yes, and easy to break. Substitution cyphers are very vulnerable to statistical measures. We know the frequency of letter usage in English (in any language) and, if we have enough text, we can figure out the encoding using those statistics. See https://en.wikipedia.org/wiki/Letter frequen How to get around this vulnerability? Well, there are many approaches but one, relatively simple, approach is to encode more than just single letters. What if we encode every pair of letters and substitute one pair for another? This is a digraph cypher, so called because pairs of letters are called digrams (also called bigrams). It was first used in the 1850's and called the Playfair cypher https://en.wikipedia.org/wiki/Playfair ciphe Why would this be any better? Well, now you have a much bigger set that you have to break. Instead of 26 substitutions, you have 26x26 substitutions (676) to find. Though digram/bigram frequency is available, the process is more difficult. We could do trigrams, quadgram, quintgrams even! http://practicalcryptography.com/cryptanalysis/letter- frequencies-various-languages/english-letter-frequencies/ but we'll stick with digrams The Playfair Algorithm Plaintext Preparation We prepare the plaintext, the string we are going to encode, as follows. we will only represent the characters a-z (minus 'j', which is not represented). Any capitalized letters are converted to lower case, Any other character is removed from the plaintext. Thus numbers, spaces, punctuation and the letter j' and 'J' areusing std::string; #include // playfair from // http://practicalcryptography.com/ciphers/classical-era/playfair/ const string alphabet_minus_j = "abcdefghiklmnopqrstuvwxyz"; const int dim = 5; string prepare_plaintext(const string &s); string create_encoding(const string &key); string encode_pair(const string &pr, const string &key); string decode_pair(const string &pr, const string &key); string encode(const string &plaintxt, const string &key); string decode(const string &encodedtxt, const string &key); #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started