Ancient Cipher’s
I started to read about old ancient Ciphers used hundreds of years ago, At the time these Ciphers where “Unbreakable” but these day they are considered unsecured, The Vigenere Cipher is more secure than the Caesar Cipher because it uses a key to encrypt text, But using the Kisiski method it can be broken if the encrypted string is long enough to analyze. Anyway here our my implementations of the Caesar and the Vigenere Ciphers
In cryptography, a Caesar cipher, also known as a Caesar’s cipher, the shift cipher, Caesar’s code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 3, A would be replaced by D, B would become E, and so on. The method is named after Julius Caesar, who used it to communicate with his generals.
The encryption step performed by a Caesar cipher is often incorporated as part of more complex schemes, such as the Vigenère cipher, and still has modern application in the ROT13 system. As with all single alphabet substitution ciphers, the Caesar cipher is easily broken and in practice offers essentially no communication security.
Function CaesarLeft(sString: String; iAmount: Integer):String; var i, iPos: Integer; sAlphabet: String; begin sAlphabet:= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; i:= 1; while i <= Length(sString) do Begin if sString[i] = ' ' then Result:= Result + ' ' else begin iPos:= pred(pos(sString[i],sAlphabet)); Result:= Result + sAlphabet[(((iPos + 26) - iAmount) mod 26) + 1]; end; inc(i); end; end; Function CaesarRight(sString: String; iAmount: Integer):String; var i, iPos: Integer; sAlphabet: String; begin sAlphabet:= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; i:= 1; while i <= Length(sString) do Begin if sString[i] = ' ' then Result:= Result + ' ' else begin iPos:= pred(pos(sString[i],sAlphabet)); Result:= Result + sAlphabet[((iPos + iAmount) mod 26) + 1]; end; inc(i); end; end;
The Vigenère cipher is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword. It is a simple form of polyalphabetic substitution.
The Vigenère (French pronunciation: [viʒnɛːʁ]) cipher has been reinvented many times. The method was originally described by Giovan Battista Bellaso in his 1553 book La cifra del. Sig. Giovan Battista Bellaso; however, the scheme was later misattributed to Blaise de Vigenère in the 19th century, and is now widely known as the “Vigenère cipher”.
This cipher is well known because while it is easy to understand and implement, it often appears to beginners to be unbreakable; this earned it the description le chiffre indéchiffrable (French for ‘the unbreakable cipher’). Consequently, many people have tried to implement encryption schemes that are essentially Vigenère ciphers, only to have them broken
Function VigenereDecrypt(sEncrypted, sKey: String): String; var i, iPosCipher, iPosKey: Integer; sString: string; begin //Create our Cipher Table sString:= 'abcdefghijklmnopqrstuvwxyz'; //Make the key the same size or greater than the Cipher while Length(sEncrypted) >= Length(sKey) do sKey:= AnsiLowercase(sKey) + AnsiLowercase(sKey); //Remove Spaces from Cipher i:=0; while i<=Length(sEncrypted) do if sEncrypted[i]=' ' then Delete(sEncrypted, i, 1) else Inc(i); //Vegenere Decryption routine i:= 1; while i <= Length(sEncrypted) do Begin iPosCipher:= pred(pos(sEncrypted[i],sString)); iPosKey := pred(pos(sKey[i],sString)); Result := Result + sString[(((iPosCipher + 26) - iPosKey) mod 26) + 1]; inc(i); end; end; Function VigenereEncrypt(sPlainText, sKey: String): String; var i, iPosText, iPosKey: Integer; sString: string; begin //Create our Cipher Table sString:= 'abcdefghijklmnopqrstuvwxyz'; //Make the key the same size or greater than the Plain Text while Length(sPlainText) >= Length(sKey) do sKey:= AnsiLowercase(sKey) + AnsiLowercase(sKey); //Remove Spaces from Cipher i:=0; while i<=Length(sPlainText) do if sPlainText[i]=' ' then Delete(sPlainText, i, 1) else Inc(i); //Vegenere Encryption routine i:= 1; while i <= Length(sPlainText) do Begin iPosText:= pred(pos(sPlainText[i],sString)); iPosKey := pred(pos(sKey[i],sString)); Result := Result + sString[((iPosText + iPosKey) mod 26) + 1]; inc(i); end; end;
Refference:

Leave a Reply