Caesars Cipher in Navision

Lately I have been reading some books about Cryptology and there I stumbled upon Caesars Cipher.

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.

Ex. with a key 3 – the letter A will become D. B will become E etc.

So the word SECRET will be come VHFUHW.

This form for cryptology can be represented by the following formular:

c = p + k mod n

where c = cipher, p = plaintext, k = key, n = number of letters in the alphabet

Letters (p) will be represented as numbers, where a = 0, b = 1 etc.

If the cipher is greater than the number of letters in the alphabet, we have to start from the begin of the alphabet – this is solved by mod.

Ex. the letter K & letter Z:

K is the 10’te letter in the alphabet. We use the key 3 and there is 26 letters in the used alphabet.

……c = p + k mod n = 10 + 3 mod 26 = 13, which gives us the letter N.

Z is the 26’te letter in the alphabet.

……c = 26 + 3 mod 26 = 29 mod 26 = 3, which gives us the letter C.

Now that the theory is on place – we can look on some functions for Navision.

To Encrypt you can use this function:

Key := 3;
NoLetters := 26;

IF TextToCrypt = ” THEN

// Remove spaces
ClearText := UPPERCASE(DELCHR(TextToCrypt,’=’,’ ‘));

// Encrypt letter by letter
FOR i := 1 TO STRLEN(ClearText) DO BEGIN

……// Char to Int – where A = 0
……ClearChar := ClearText[i] – 65;

……//Encrypt char – +65 to get a letter
……CryptChar := ((ClearChar + Key) MOD NoLetters) + 65;

……// Add char to crypt text
……CryptText += FORMAT(CryptChar);

TextToCrypt := UPPERCASE(TextToCrypt);

Ok now you can encrypt – but what about decryption. Decryption is actually the same as encryption – all you have to do, is to use a different key :-)

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 – key = 23).

Decrypt example:

Key := 3;
NoLetters := 26;
DecryptKey := NoLetters – Key;

IF CryptText = ” THEN

//DeCrypt letter by letter
FOR i := 1 TO STRLEN(CryptText) DO BEGIN

……//Char to Int – where A = 0
……CryptChar := CryptText[i] – 65;

……//Encrypt char – +65 to get a letter
……ClearChar := ((CryptChar + DecryptKey) MOD NoLetters) + 65;

……// Add char to crypt text
……DeCryptText += FORMAT(ClearChar);

If you compare the two functions, you will see that the encryption and decryptions functions are pretty much the same – they only use different keys.

Now you can encrypt and decrypt with Caesars Cipher in Navision :-)

You can leave a response, or trackback from your own site.

6 Responses to “Caesars Cipher in Navision”

  1. Jens says:

    Nice work :-) Lad mig gætte; du læste også Digital Fortress og blev også skuffet/irriteret over Dan Browns lemfældige/sløsede omgang med virkeligheden. Men kunne alligevel ikke helt slippe de ‘kryptiske’/finurlige tankegange i hans bog?

  2. iby says:

    Tak! Hvor kunne du gætte det ;-)

    Har tidligere beskræftiget mig med kryptering og efter at jeg havde læst Digital Fortress, valgte jeg at genopfriske hukommelsen og opdatere min viden på området.

    Da jeg i hverdagen arbejder med Navision – kunne jeg ikke lade være med at teste Cæsars krypteringsmetode i denne.

    Hvem ved måske, laver jeg et indlæg om andre metoder på et tidspunkt ;-)

    And for you guys & gals – that doesn’t understand Danish. In short terms… I’m just telling Jens, that my inspiration to this article was Digital Fortress from Dan Brown and that I might in the future write an article about another Cryptation method.

  3. sandra407 says:

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  4. Rusasteappaky-web says:

    behovet for at se:)

  5. informal wedding gowns says:

    I just study car piece of yours and it had been very good. This is a excellent article thank you for sharing this informative info. I’ll visit your blog frequently for some most recent post.

  6. backup software says:

    What’s up to all, the contents existing at this site are
    truly amazing for people knowledge, well, keep up the nice work fellows.

Leave a Reply

two × 9 =