<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TechBlog &#187; Cryptology</title>
	<atom:link href="http://techblog.byllemos.com/tag/cryptology/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.byllemos.com</link>
	<description>Accelerating into the Future with Wisdom about Technology! Ingrid Byllemos</description>
	<lastBuildDate>Tue, 05 Jan 2010 00:04:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Playfair Cipher in Navision</title>
		<link>http://techblog.byllemos.com/2008/11/playfair-cipher-in-navision/</link>
		<comments>http://techblog.byllemos.com/2008/11/playfair-cipher-in-navision/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 20:00:56 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[Navision]]></category>
		<category><![CDATA[Cryptology]]></category>
		<category><![CDATA[Playfair]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=88</guid>
		<description><![CDATA[<p>As earlier mentioned I have being reading some books about Cryptology &#8211; and now its Playfairs turn to be tested in Navision <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Playfair Cipher (aka. Playfair square) is a symmetric encryption technique and was&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>As earlier mentioned I have being reading some books about Cryptology &#8211; and now its Playfairs turn to be tested in Navision <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Playfair Cipher (aka. Playfair square) is a symmetric encryption technique and was the first literal digraph substitution cipher. It was invented by Charles Wheatstone and popularized by Lyon Playfair.</p>
<p>The technique encrypts pairs of letters instead of single letters, which means it is a type of digraph cipher.<br />
<span id="more-88"></span><br />
The Playfair Cipher is significantly harder to break since the frequency analysis used for simple substitution ciphers does not work with it. So its no wonder, that is was used during both the first and second world war.</p>
<p>Lets take a closer look. First we have to choose a key, as example we will use &#8220;JULEMANDEN&#8221;.<br />
The Playfair cipher uses a 5 by 5 table containing a key word or phrase, where the phrase normally will be the alphabet. So the key &#8220;JULEMANDEN&#8221; will become:</p>
<blockquote>
<table>
<tr>
<td>I</td>
<td>U</td>
<td>L</td>
<td>E</td>
<td>M</td>
</tr>
<tr>
<td>A</td>
<td>N</td>
<td>D</td>
<td>B</td>
<td>C</td>
</tr>
<tr>
<td>F</td>
<td>G</td>
<td>H</td>
<td>K</td>
<td>O</td>
</tr>
<tr>
<td>P</td>
<td>Q</td>
<td>R</td>
<td>S</td>
<td>T</td>
</tr>
<tr>
<td>V</td>
<td>W</td>
<td>X</td>
<td>Y</td>
<td>Z</td>
</tr>
</table>
</blockquote>
<p>How did this key be generated? Well first we took JULEMANDEN and removed duplicated letters &#8211; after this we where left with JULEMAND. </p>
<p>Next we replaced J with I. J &#038; I are represented by the same letter. </p>
<p>Finally we split it up into a 5 x 5 square, and filled the missing field values with letters from the alphabet.</p>
<p>This is how it could be done in Navision:</p>
<blockquote><p>
//convert j to i<br />
inKey := CONVERTSTR(inKey,&#8217;j',&#8217;i');</p>
<p>//Remove duplicates<br />
FOR i := 1 TO STRLEN(inKey) DO BEGIN<br />
<font class="blankspace">&#8230;&#8230;</font>IF STRPOS(outKey,FORMAT(Key[i])) = 0 THEN<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>outKey += FORMAT(inKey[i]);<br />
END;</p>
<p>//Put in fill chars<br />
alphabet := &#8216;abcdefghiiklmnopqrstuvwxyz&#8217;;<br />
aIndex := 1;<br />
WHILE STRLEN(outKey) < 25 DO BEGIN<br />
<font class="blankspace">&#8230;&#8230;</font>IF STRPOS(outKey, FORMAT(alphabet[aIndex])) = 0 THEN<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>outKey += FORMAT(alphabet[aIndex]);<br />
<font class="blankspace">&#8230;&#8230;</font>aIndex += 1;<br />
END;
</p></blockquote>
<p>Now that the key is in place, we will focus on the encryption. </p>
<p>Lets try to encrypt the text: &#8220;this is encrypted&#8221;. Before the text can be encrypt it has to prepared. The preparation will go through the following steps:</p>
<ul>
<li>Remove spaces</li>
<li>Remove unsupported letters. Ex. dot, numbers and localized letters ex. æøå</li>
<li>Replace j with i</li>
<li>If two letters are the same, then add a X. Ex. &#8220;this show&#8221; would be &#8220;this xshow&#8221;</li>
<li>If text length is odd then add a X to the end</li>
</ul>
<p>Finally break the message into digraphs (groups of 2 letters). So before starting the encryption the prepared text would look like this:</p>
<blockquote>
<table>
<tr>
<td>Text:</td>
<td>this is encrypted</td>
</tr>
<tr>
<td>Prepared Text: </td>
<td>th is is en cr yp te dx</td>
</tr>
</table>
</blockquote>
<p>And as an Navision example:</p>
<blockquote><p>
orgText := LOWERCASE(orgText);</p>
<p>//Remove not supported signs &#8211; only letters are supported!<br />
orgText := DELCHR(orgText,&#8217;=',&#8217; .,0123456789æøå&#8217;);<br />
orgText := CONVERTSTR(orgText,&#8217;j',&#8217;i');</p>
<p>//If the seond letter of a pair is the same as the first letter, then use x.<br />
i := 1;<br />
WHILE i <= STRLEN(orgText) DO BEGIN</p>
<p><font class="blankspace">&#8230;&#8230;</font>nextChar := FORMAT(orgText[i]);<br />
<font class="blankspace">&#8230;&#8230;</font>IF (i > 1) THEN<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>IF orgText[i] = orgText[i-1] THEN<br />
<font class="blankspace">&#8230;&#8230;&#8230;&#8230;&#8230;.</font>nextChar := &#8216;x&#8217; + FORMAT(orgText[i]);</p>
<p><font class="blankspace">&#8230;&#8230;</font>preText += nextChar;<br />
<font class="blankspace">&#8230;&#8230;</font>i += 1;<br />
END;</p>
<p>//If string length is odd then add x<br />
IF (STRLEN(preText) MOD 2) = 1 THEN<br />
<font class="blankspace">&#8230;&#8230;</font>preText += &#8216;x&#8217;;
</p></blockquote>
<p>Now lets do the encryption by looking on the individual groups and their placement in the key.<br />
To encrypt a group we use the following rules:
<ul>
<li>Is both letters in the same Row? If yes then take the next letter in the row</li>
<li>Is both letters in the same Column? If yes then take the next letter in the column</li>
<li>If none off the above occur, the rule differs. To encrypt the first letter, look along its row until the column containing the second letter is reached &#8211; the letter at this intersection replaces the first letter. To encrypt the second letter, look along its row until the column containing the first letter is reached &#8211; the letter at this intersection replaces the second letter. Hence, &#8216;th&#8217; becomes &#8216;ro&#8217;.</li>
</ul>
<p>The encrypted text will therefor become:</p>
<blockquote>
<table>
<tr>
<td>Text:</td>
<td>this is encrypted</td>
</tr>
<tr>
<td>Encrypted:</td>
<td>ro ep ep ub dt vs sm hl</td>
</tr>
</table>
</blockquote>
<p>This is how it could be done in Navision:</p>
<blockquote><p>
i := 1;<br />
FOR i := 1 TO STRLEN(preText) DO BEGIN</p>
<p><font class="blankspace">&#8230;&#8230;</font>Index1 := STRPOS(KeyIndex,FORMAT(preText[i]));<br />
<font class="blankspace">&#8230;&#8230;</font>row1 := ROUND(Index1 / 5,1,&#8217;>');<br />
<font class="blankspace">&#8230;&#8230;</font>col1 := Index1 MOD 5;<br />
<font class="blankspace">&#8230;&#8230;</font>IF col1 = 0 THEN col1 := 5;</p>
<p><font class="blankspace">&#8230;&#8230;</font>Index2 := STRPOS(KeyIndex,FORMAT(preText[i+1]));<br />
<font class="blankspace">&#8230;&#8230;</font>row2 := ROUND(Index2 / 5,1,&#8217;>');<br />
<font class="blankspace">&#8230;&#8230;</font>col2 := Index2 MOD 5;<br />
<font class="blankspace">&#8230;&#8230;</font>IF col2 = 0 THEN col2 := 5;</p>
<p><font class="blankspace">&#8230;&#8230;</font>i += 1;</p>
<p><font class="blankspace">&#8230;&#8230;</font>//The letters are in the same Row<br />
<font class="blankspace">&#8230;&#8230;</font>IF row1 = row2 THEN BEGIN<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>colpos := NextPos(col1);<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>Index1 := ((row1 &#8211; 1) * 5) + colpos;</p>
<p><font class="blankspace">&#8230;&#8230;&#8230;..</font>colpos := NextPos(col2);<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>Index2 := ((row2 &#8211; 1) * 5) + colpos;</p>
<p><font class="blankspace">&#8230;&#8230;&#8230;..</font>crypText += (FORMAT(KeyIndex[Index1]) + FORMAT(KeyIndex[Index2]));</p>
<p><font class="blankspace">&#8230;&#8230;</font>//The Letters are in the same Column<br />
<font class="blankspace">&#8230;&#8230;</font>END ELSE IF col1 = col2 THEN BEGIN<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>rowpos := NextPos(row1);<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>Index1 := ((rowpos &#8211; 1) * 5) + col1;</p>
<p><font class="blankspace">&#8230;&#8230;&#8230;..</font>rowpos := NextPos(row2);<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>Index2 := ((rowpos &#8211; 1) * 5) + col2;</p>
<p><font class="blankspace">&#8230;&#8230;&#8230;..</font>crypText += (FORMAT(KeyIndex[Index1]) + FORMAT(KeyIndex[Index2]));</p>
<p><font class="blankspace">&#8230;&#8230;</font>//Letters are in a square<br />
<font class="blankspace">&#8230;&#8230;</font>END ELSE BEGIN<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>rowpos := NextPos(row1 &#8211; 1);<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>Index1 := ((rowpos &#8211; 1) * 5) + col2;</p>
<p><font class="blankspace">&#8230;&#8230;&#8230;..</font>rowpos := NextPos(row2 &#8211; 1);<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>Index2 := ((rowpos &#8211; 1) * 5) + col1;</p>
<p><font class="blankspace">&#8230;&#8230;&#8230;..</font>crypText += (FORMAT(KeyIndex[Index1]) + FORMAT(KeyIndex[Index2]));<br />
<font class="blankspace">&#8230;&#8230;</font>END;</p>
<p>END;
</p></blockquote>
<p>Where NextPos is calculated in this way:</p>
<blockquote><p>
NewPos := (Pos + 1) MOD 5;<br />
IF NewPos = 0 THEN<br />
<font class="blankspace">&#8230;&#8230;</font>NewPos := 5;
</p></blockquote>
<p>To decrypt &#8211; just do the inverse <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Now you are able to encrypt with Playfair in Navision.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/11/playfair-cipher-in-navision/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Caesars Cipher in Navision</title>
		<link>http://techblog.byllemos.com/2008/09/caesar-cipher-in-navision/</link>
		<comments>http://techblog.byllemos.com/2008/09/caesar-cipher-in-navision/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 21:01:10 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[Navision]]></category>
		<category><![CDATA[Caesar Cipher]]></category>
		<category><![CDATA[Cryptology]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=72</guid>
		<description><![CDATA[<p>Lately I have been reading some books about Cryptology and there I stumbled upon Caesars Cipher.</p>
<p>Caesars Cipher is a very simple form of Cryptation. Its method is to  replace each plaintext letter with one a fixed number of places&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Lately I have been reading some books about Cryptology and there I stumbled upon Caesars Cipher.</p>
<p>Caesars Cipher is a very simple form of Cryptation. Its method is to  replace each plaintext letter with one a fixed number of places down the alphabet. The fixed number is the Key.</p>
<p>Ex. with a key 3 &#8211; the letter A will become D. B will become E etc.</p>
<p>So the word <strong>SECRET</strong> will be come <strong>VHFUHW</strong>.<br />
<span id="more-72"></span><br />
This form for cryptology can be represented by the following formular:</p>
<blockquote><p>
c = p + k mod n</p>
<p>where c = cipher, p = plaintext, k = key, n = number of letters in the alphabet
</p></blockquote>
<p>Letters (p) will be represented as numbers, where a = 0, b = 1 etc.</p>
<p>If the cipher is greater than the number of letters in the alphabet, we have to start from the begin of the alphabet &#8211; this is solved by mod.</p>
<p>Ex. the letter K &#038; letter Z:</p>
<blockquote><p>
K is the 10&#8242;te letter in the alphabet. We use the key 3 and there is 26 letters in the used alphabet.</p>
<p><font class="blankspace">&#8230;&#8230;</font>c = p + k mod n = 10 + 3 mod 26 = 13, which gives us the letter N.</p>
<p>Z is the 26&#8242;te letter in the alphabet.</p>
<p><font class="blankspace">&#8230;&#8230;</font>c = 26 + 3 mod 26 = 29 mod 26 = 3, which gives us the letter C.
</p></blockquote>
<p>Now that the theory is on place &#8211; we can look on some functions for Navision.</p>
<p>To Encrypt you can use this function:</p>
<blockquote><p>
Key := 3;<br />
NoLetters := 26;</p>
<p>IF TextToCrypt = &#8221; THEN<br />
<font class="blankspace">&#8230;&#8230;</font>EXIT;</p>
<p>// Remove spaces<br />
ClearText := UPPERCASE(DELCHR(TextToCrypt,&#8217;=',&#8217; &#8216;));</p>
<p>// Encrypt letter by letter<br />
FOR i := 1 TO STRLEN(ClearText) DO BEGIN</p>
<p><font class="blankspace">&#8230;&#8230;</font>// Char to Int &#8211; where A = 0<br />
<font class="blankspace">&#8230;&#8230;</font>ClearChar := ClearText[i] &#8211; 65;</p>
<p><font class="blankspace">&#8230;&#8230;</font>//Encrypt char &#8211; +65 to get a letter<br />
<font class="blankspace">&#8230;&#8230;</font>CryptChar := ((ClearChar + Key) MOD NoLetters) + 65;</p>
<p><font class="blankspace">&#8230;&#8230;</font>// Add char to crypt text<br />
<font class="blankspace">&#8230;&#8230;</font>CryptText += FORMAT(CryptChar);<br />
END;</p>
<p>TextToCrypt := UPPERCASE(TextToCrypt);
</p></blockquote>
<p>Ok now you can encrypt &#8211; but what about decryption. Decryption is actually the same as encryption &#8211; all you have to do, is to use a different key <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>So which key to use? The key to encrypt was 3 and the number of letters was 26. To decrypt you have to deduct 3 letters. This gives us the decrypt key equals 23 (number of letters &#8211; key = 23).</p>
<p>Decrypt example:</p>
<blockquote><p>
Key := 3;<br />
NoLetters := 26;<br />
DecryptKey := NoLetters &#8211; Key;</p>
<p>IF CryptText = &#8221; THEN<br />
<font class="blankspace">&#8230;&#8230;</font>EXIT;</p>
<p>//DeCrypt letter by letter<br />
FOR i := 1 TO STRLEN(CryptText) DO BEGIN</p>
<p><font class="blankspace">&#8230;&#8230;</font>//Char to Int &#8211; where A = 0<br />
<font class="blankspace">&#8230;&#8230;</font>CryptChar := CryptText[i] &#8211; 65;</p>
<p><font class="blankspace">&#8230;&#8230;</font>//Encrypt char &#8211; +65 to get a letter<br />
<font class="blankspace">&#8230;&#8230;</font>ClearChar := ((CryptChar + DecryptKey) MOD NoLetters)  + 65;</p>
<p><font class="blankspace">&#8230;&#8230;</font>// Add char to crypt text<br />
<font class="blankspace">&#8230;&#8230;</font>DeCryptText += FORMAT(ClearChar);<br />
END;
</p></blockquote>
<p>If you compare the two functions, you will see that the encryption and decryptions functions are pretty much the same &#8211; they only use different keys.</p>
<p>Now you can encrypt and decrypt with Caesars Cipher in Navision <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/09/caesar-cipher-in-navision/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

