{"id":1127,"date":"2010-10-28T16:28:10","date_gmt":"2010-10-28T20:28:10","guid":{"rendered":"http:\/\/www.acarlstein.com\/?p=1127"},"modified":"2010-11-02T15:55:20","modified_gmt":"2010-11-02T19:55:20","slug":"introduction-to-network-security-part-5","status":"publish","type":"post","link":"http:\/\/blog.acarlstein.com\/?p=1127","title":{"rendered":"Introduction to Network Security &#8211; Part 5"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\"><strong>NOTIFICATION:<\/strong><\/span><strong> <\/strong>These examples are provided for educational purposes.     The use of this code and\/or information is under your own responsibility and risk. The information and\/or code is     given \u2018as is\u2019. I do not take responsibilities of how they are used.<\/p>\n<p><strong>Symmetric Encryption<\/strong><\/p>\n<p>In the symmetric encryption, the same key (normally a single-key) is  used to perform the encryption and decryption of the ciphertext.<\/p>\n<p><span style=\"text-decoration: underline;\">Symmetric Cipher Model:<\/span> This model is performed by performing  transformations and substitutions on the plaintext. A secret key,  independent from the plaintext and the algorithm, is used to cipher the  plaintext. After, the ciphertext plus the secret key is used with the  decryption algorithm to obtain the original plaintext.<\/p>\n<p>Symmetric Encryption is the opposite to the concept of public key distribution which will be explained in future postings.<\/p>\n<p><span style=\"text-decoration: underline;\">Requirements:<\/span><\/p>\n<ol>\n<li>The cipher model must be mathematical expression:<br \/>\n(E: Encryption, D: Decryption, X: plaintext, Y: ciphertext, K: secret key)<\/p>\n<pre>Y = E(K, X)\r\nX = D(K, Y)\r\n<\/pre>\n<\/li>\n<li>Assumption that the encryption algorithm is known to the attacker.<\/li>\n<li>A strong encryption algorithm which in case the attacker would  obtain or know some examples of the ciphertext and the plaintext  produced from the ciphertext, the attacker would still be not able to  obtain the key. This means that if the attacker would obtain the  ciphertext, the attacker would not be able to obtain the secret key or  the plain text.<\/li>\n<li>Secret key should be known only by the sender and the receiver of the ciphertext.<\/li>\n<li>The distribution of the secret key must be done in a secure fashion.  For example, the use of a third party that would generate and provide  in a secure way the key to the sender and the receiver.<\/li>\n<\/ol>\n<p><strong>Substitution Ciphers<\/strong><\/p>\n<p>In classical substitution ciphers, all the letters in the plaintext will be replaced by another letter, number, and\/or symbol.<\/p>\n<p><strong>Caesar Cipher<\/strong><\/p>\n<p>History explains that Julius Caesar &lt;<a href=\"http:\/\/www.roman-empire.net\/republic\/caesar-index.html\" target=\"_blank\">http:\/\/www.roman-empire.net\/republic\/caesar-index.html<\/a>&gt; came up with a substitution cipher that he used in his campaigns for military affairs.<\/p>\n<p>The cipher works in the following way:<\/p>\n<ol>\n<li>We use the alphabet of 26 letters:\n<pre><a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/alphabet-table-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1143\" title=\"alphabet table 1\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/alphabet-table-1.jpg\" alt=\"\" width=\"535\" height=\"70\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/alphabet-table-1.jpg 679w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/alphabet-table-1-300x39.jpg 300w\" sizes=\"auto, (max-width: 535px) 100vw, 535px\" \/><\/a>\r\n<\/pre>\n<\/li>\n<li>Under this alphabet, we will rewrite the alphabet by picking a letter as a starting point.<br \/>\nLets say our key indicate the starting point such as K = 4 so we begin with the letter &#8216;E&#8217; then:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/alphabet-table-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1144\" title=\"alphabet table 2\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/alphabet-table-2.jpg\" alt=\"\" width=\"529\" height=\"69\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/alphabet-table-2.jpg 682w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/alphabet-table-2-300x39.jpg 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/a><\/li>\n<li>This means that if we wish to send a plaintext (P) that says HELLO, the ciphertext (C) would be LIPPS, and the key (K) would be 4<\/li>\n<li>The mathematical way to represent this cipher will be the follows:\n<ol>\n<li>Give each letter of the alphabet a number:<br \/>\nA = 1, B = 2, C = 3, D = 4, E = 5,F = 6, G = 7, H = 8, J = 9, K = 10, L = 11, M = 12, N = 13, O = 14,P = 15, Q = 16, R = 17, S = 18, T = 19, U = 20, V = 21, W = 22, X = 23, Y = 24, Z = 25.<\/li>\n<li>Encryption Algorithm:<br \/>\nE: Encryption, Ct: Ciphertext, Pt: Plaintext, K: secret key<\/p>\n<pre>Ct = E(Pt)\r\n   = (Pt + K) mod 26<\/pre>\n<\/li>\n<li>Decryption Algorithm:<br \/>\nD: Decryptor, Ct: Ciphertext, Pt: Plaintext, K: secret key<\/p>\n<pre>Pt = D(Ct)\r\n   = (26 + (Ct - K)) mod 26<\/pre>\n<\/li>\n<\/ol>\n<\/li>\n<li>The weakness of this cipher is that it can be broken by brute force. We just need to test the 25 combinations of different keys\u00a0 until we find the key that reveals the message.<\/li>\n<\/ol>\n<p><strong>Monoalphabetic Cipher<\/strong><\/p>\n<p>The mono-alphabetic cipher instead of shifting the alphabet a number of letters, its substitute each letter arbitrarily by mapping the plaintext letter map to a random arranged ciphertext. The only requirement for the ciphertext is that the letters must not be repeated.<\/p>\n<p>Since we are using 26 letters of the alphabet the arrangement of the cipher can permute a total of 26! permutations.<\/p>\n<p><a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/table-alphabets-234.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1150\" title=\"table alphabets 234\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/table-alphabets-234.jpg\" alt=\"\" width=\"517\" height=\"73\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/table-alphabets-234.jpg 694w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/table-alphabets-234-300x42.jpg 300w\" sizes=\"auto, (max-width: 517px) 100vw, 517px\" \/><\/a><\/p>\n<p>If we wish to encode the word &#8220;HELLO&#8221;, we would obtain &#8220;NERRS&#8221;<\/p>\n<p>Lets assume we wish to cipher a plaintext:<\/p>\n<p>Plaintext = &#8220;THIS IS A SECRET MESSAGE ENCODED IN MONOALPHABETIC&#8221;<\/p>\n<p>Ciphertext = &#8220;XNMW MW E WIGBIX OIWWEJI IPGSCIC MP OSPSERUEDIXMG&#8221;<\/p>\n<p>The following website let you play a little with monoalphabetic cipher by randomizing for you the ciphertext:<br \/>\n&lt;<a href=\"http:\/\/www.simonsingh.net\/The_Black_Chamber\/generalsubstitutionWithMenu.html\">http:\/\/www.simonsingh.net\/The_Black_Chamber\/generalsubstitutionWithMenu.html<\/a>&gt;<\/p>\n<p>The only problem is that this cipher can be exploited by doing regularities analysis over the frequency of the letters. Base on the language rules some letters are used more than others. For example, in English, the letter &#8216;E&#8217; is the most common used in words, followed by A, I, O, N, R, S, T. Others letters such as K, J, Q, X, Z are less used than the rest.<\/p>\n<p>The largest is the message, the most chances that the attacker can decrypt the message.<br \/>\nJust in this message &#8220;XNMW MW E WIGBIX OIWWEJI IPGSCIC MP OSPSERUEDIXMG&#8221; we have:<\/p>\n<ul>\n<li>W = 6 letters<\/li>\n<li>E = 4 letters<\/li>\n<li>M = 4 letters<\/li>\n<li>S = 3 letters<\/li>\n<li>P = 2 letters<\/li>\n<li>&#8230;.<\/li>\n<\/ul>\n<p>And continue counting.<\/p>\n<p>As you may notice the letter &#8216;W&#8217; of the encrypted message have the most counts, so we could\u00a0 assume that this is the letter E of the plaintext.<\/p>\n<p>If you are interested to know the frequency of letters in English you can go to the following website:<br \/>\n&lt;<a href=\"http:\/\/www.cryptograms.org\/letter-frequencies.php\">http:\/\/www.cryptograms.org\/letter-frequencies.php<\/a>&gt;<\/p>\n<p>For more information about attacking mono-alphabetic cipher, there is a good example on this website:<br \/>\n&lt;<a href=\"http:\/\/unsecure.co.uk\/attackingmonoalphabeticciphers.asp\">http:\/\/unsecure.co.uk\/attackingmonoalphabeticciphers.asp&gt;<\/a><\/p>\n<p><strong>Playfair Cipher<\/strong><\/p>\n<p>Playfair is one way to improve the security of mono-alphabetic cipher by encrypting multiple letters.<\/p>\n<p><span style=\"text-decoration: underline;\">Playfair Encryption<\/span><\/p>\n<ol>\n<li>Create a playfair key matrix:\n<ol>\n<li>Create a matrix of letters based on a keyword. For this example, the matrix should be 5 by 5<\/li>\n<li>Fill in the letters of the keyword from left to right and from top to bottom. Make sure that there are not duplicate letters<\/li>\n<li>Fill the rest of the matrix with the other letters that are not in the keyboard, making sure to not duplicate letters.<\/li>\n<li>As a rule, the letter I and J count as one letter.\n<ul>\n<li>I am not sure the reason for this rule, except the following:\n<ul>\n<li>First, it make it harder to decrypt the message since one letter is missing.<\/li>\n<li>Second, in some languages, the J and I would have the same pronunciation.<br \/>\nFor example, my last name Carlstein was originally written as Karl\u0161tejn.<\/li>\n<\/ul>\n<\/li>\n<li>In case you know the real reason, please let me know and give me a reference to verify (thanks).<\/li>\n<\/ul>\n<\/li>\n<li>Example of playfair key matrix:\n<ol>\n<li>Let use the keyword: &#8220;EDUCATOR&#8221;<\/li>\n<li>The table should looks like this:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/5-by-5-matrix-fair-play.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1158\" title=\"5 by 5 matrix fair play\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/5-by-5-matrix-fair-play.jpg\" alt=\"\" width=\"251\" height=\"161\" \/><\/a><\/li>\n<li>Notice that I and J are counted as one letter<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>The next step is to encrypt the plaintext taking two letters at the time.\n<ol>\n<li>In case a two letters are the same (repeated), we must insert a filler letter (use the letter X as the filler). For example:<br \/>\nHELLO \u2192 HE LX LO<\/li>\n<li>In case two letters are in the same row, <span style=\"text-decoration: underline;\">replace each letter with the letter to the <\/span><span style=\"text-decoration: underline;\">right<\/span>. In case the letter is at the last column, pick the letter of the first row (the table is considerate to be circular). For example, lets say we have the letters D and A:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_encrypt_1.jpg\"><\/a><a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_encrypt_11.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1167\" title=\"playfair_encrypt_1\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_encrypt_11.jpg\" alt=\"\" width=\"498\" height=\"109\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_encrypt_11.jpg 716w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_encrypt_11-300x65.jpg 300w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><\/a><\/p>\n<ol>\n<li>D \u2192 U and A \u2192 E<\/li>\n<li>Therefore DA became UE<\/li>\n<\/ol>\n<\/li>\n<li>In case two letters are in the same column, <span style=\"text-decoration: underline;\">replace each letter with the letter below<\/span>. In case the letter is at the last row, pick the letter of the first row (the table is considerate to be circular). For example, lets say we have the letters T and V:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_encrypt_2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1165\" title=\"playfair_encrypt_2\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_encrypt_2.jpg\" alt=\"\" width=\"396\" height=\"234\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_encrypt_2.jpg 550w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_encrypt_2-300x177.jpg 300w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/a><\/p>\n<ol>\n<li>T \u2192 G and V \u2192 E<\/li>\n<li>Therefore TV became GE<\/li>\n<\/ol>\n<\/li>\n<li>In case two letter are in different row and column, the first letter will be replaced with another letter of the same row on the column of the second letter. The second letter will be replaced with another letter of the same row on the column of the first letter. For example lets say we have the letters O and Q:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_encrypt_3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1166\" title=\"playfair_encrypt_3\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_encrypt_3.jpg\" alt=\"\" width=\"468\" height=\"173\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_encrypt_3.jpg 676w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_encrypt_3-300x110.jpg 300w\" sizes=\"auto, (max-width: 468px) 100vw, 468px\" \/><\/a><\/p>\n<ol>\n<li>To replace the letter O:\n<ol>\n<li>This means that O \u2192 B<\/li>\n<\/ol>\n<\/li>\n<li>To replace the letter Q:\n<ol>\n<li>This means that Q \u2192 N<\/li>\n<\/ol>\n<\/li>\n<li>Therefore OQ became BN<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\">Playfair Decryption:<\/span><\/p>\n<ol>\n<li>Decrypt two letters at a time:\n<ol>\n<li>In case two letters are in the same row, <span style=\"text-decoration: underline;\">replace each letter with the letter to the left<\/span>.  In case the letter is at the last column, pick the letter of the first  row (the table is considerate to be circular). For example, lets say we  have the letters U and E:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1168\" title=\"playfair_decrypt_cipher_1\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_1.jpg\" alt=\"\" width=\"463\" height=\"97\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_1.jpg 719w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_1-300x63.jpg 300w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><\/a><\/p>\n<ol>\n<li>U \u2192 D and E \u2192 A<\/li>\n<li>Therefore UE became DA<\/li>\n<\/ol>\n<\/li>\n<li>In case two letters are in the same column, <span style=\"text-decoration: underline;\">replace each letter with  the letter above<\/span>. In case the letter is at the last row, pick the  letter of the first row (the table is considerate to be circular). For  example, lets say we have the letters G and E:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1169\" title=\"playfair_decrypt_cipher_2\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_2.jpg\" alt=\"\" width=\"405\" height=\"257\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_2.jpg 544w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_2-300x190.jpg 300w\" sizes=\"auto, (max-width: 405px) 100vw, 405px\" \/><\/a><\/p>\n<ol>\n<li>G \u2192 T and E \u2192 V<\/li>\n<li>Therefore GE became TV<\/li>\n<\/ol>\n<\/li>\n<li>In case two letter are in different row and column, the first letter  will be replaced with another letter of the same row on the column of  the second letter. The second letter will be replaced with another  letter of the same row on the column of the first letter. For example  lets say we have the letters B and N:<br \/>\n<a href=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1170\" title=\"playfair_decrypt_cipher_3\" src=\"http:\/\/www.elblender.com\/wordpress\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_3.jpg\" alt=\"\" width=\"478\" height=\"163\" srcset=\"http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_3.jpg 688w, http:\/\/blog.acarlstein.com\/wp-content\/uploads\/2010\/10\/playfair_decrypt_cipher_3-300x102.jpg 300w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><\/a><\/p>\n<ol>\n<li>To replace the letter B:\n<ol>\n<li>This means that O \u2192 B<\/li>\n<\/ol>\n<\/li>\n<li>To replace the letter Q:\n<ol>\n<li>This means that Q \u2192 N<\/li>\n<\/ol>\n<\/li>\n<li>Therefore OQ became BN<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>After you will finish with the final message. You must remove any extra X that do not make sense in the message:<br \/>\nHE LX LO \u2192 HELLO<\/li>\n<\/ol>\n\n<script>\nvar zbPregResult = '0';\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>NOTIFICATION: These examples are provided for educational purposes. The use of this code and\/or information is under your own responsibility and risk. The information and\/or code is given \u2018as is\u2019. I do not take responsibilities of how they are used. Symmetric Encryption In the symmetric encryption, the same key (normally a single-key) is used to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,264],"tags":[42,349,197,352,217,316,321,323,346,338,350,324,351,335,348,334],"class_list":["post-1127","post","type-post","status-publish","format-standard","hentry","category-programming","category-network-security","tag-algorithm","tag-alphabet","tag-alphabetic","tag-caesar","tag-cipher","tag-ciphertext","tag-decryption","tag-encryption","tag-julius","tag-key","tag-monoalphabetic","tag-plaintext","tag-playfair","tag-secret","tag-substitution","tag-symmetric"],"_links":{"self":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1127"}],"version-history":[{"count":28,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1127\/revisions"}],"predecessor-version":[{"id":1192,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=\/wp\/v2\/posts\/1127\/revisions\/1192"}],"wp:attachment":[{"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1127"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.acarlstein.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}