top of page
Writer's pictureVlad

CRYPT[1] - CAESAR CIPHER(Algorithm,Code, Exploit)



One main aspect of paranoia with regards to cybersecurity is a secure channel of communication between an entity. A security paranoid guy would always make sure that his data was delivered to his receiver without his data being tampered or an unauthorized access of an evil man-in-the-middle in any forms of communication. Thus me made sure that the message we delivered is 'encrypted'(maintaining the confidentiality of data by converting a plain text of information to cipher text)


In this blog we will dig the ground in search for a better understanding on one of the earliest mode of encryption created in the history of mankind,the Caesar Cipher.


Caesar Cipher was named after Julius Caesar who used a shift of 3(key value) to protect his messages of military significance. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions further down the alphabet. It is in this type of encryption that character is incremented by a value, 'key'. The use of this key is to ensure that if someone figures out the algorithm, they won't be able to decrpyt the message unless they know the value of the key.


ALGORITHM

So let's say that the key would be 3, the new value of alphabet would be forward shift 3 places from its original, so...


A = D, B = E, C = F...


Using a modular approach, we can describe this encryption by assigning letters to numbers respectively,

A=0, B=1, C=2, D=3...Z=25


Mathematically speaking using the number theory, we can derived the formula of a Caesar Cipher to:



where x = alphabet

n = key or the number of shifts


pseudocode

Deriving the mathematical formula above to its equivalent code...


message = {user input} #plain text sender's input


key = number of shift

alphabet_check = {list of alphabets}


mode_of_encryption = {options would be encrypt or decrypt}


new_word = ''


#cipher text process#

for mes in alphabet_check:

mes = mes.upper() #convert to capital letters


for x in mes:

if x in alphabet_check:

#parse the numerical value of letter from the input message

n = alphabet_check.find()


#application of the formula from above

if mode is encrypt

n = n + key

else if mode is decrypt

n = n - key[len(alphabet_check)]


new_word = new_word + alphabet_check[n]


else:


new_word = new_word + x


$cenario #1:

Pepa left a note on Popo before she get to work. Below is the text she wrote on a piece of paper.


CSYV JEZSVMXI TMI MW MR XLI JVMHKI


Lovingly,

Pepa


Assuming that Popo knows that the key is 4...




$cenario #2:


Jesse texted Randy informing him that he changed the passcode of their safe. Below is the text message


Randy, I changed the note of our safe to EVFCVOZTRC. The key is your age when dad bought you your first bike.


In this scenerio Jesse knows that Randy will know that the key is 9 for this event is something that Randy will never forget.



$cenario #3:

IMF agent Ethan Hunt was on to another mission. Below was the message he received from Commander Swanbeck


"

MUUJ SUXTOTM, SX. NATZ. EUAX SOYYOUT, YNUARJ EUA INUUYK ZU GIIKVZ OZ, OTBURBKY ZNK XKIUBKXE UL G YZURKT OZKS JKYOMTGZKJ "INOSKXG."EUA SGE YKRKIZ GTE ZCU ZKGS SKSHKXY, HAZ OZ OY KYYKTZOGR ZNGZ ZNK ZNOXJ SKSHKX UL EUAX ZKGS HK TEGN TUXJULL-NGRR.YNK OY G IOBOROGT, GTJ G NOMNRE IGVGHRK VXULKYYOUTGR ZNOKL.EUA NGBK LUXZE-KOMNZ NUAXY ZU XKIXAOZ SOYY NGRR GTJ SKKZ SK OT YKBORRK ZU XKIKOBK EUAX GYYOMTSKTZ.GY GRCGEY, YNUARJ GTE SKSHKX UL EUAX ZKGS HK IGAMNZ UX QORRKJ, ZNK YKIXKZGXE CORR JOYGBUC GRR QTUCRKJMK UL EUAX GIZOUTY.GTJ SX. NATZ, ZNK TKDZ ZOSK EUA MU UT NUROJGE, VRKGYK HK MUUJ KTUAMN ZU RKZ AY QTUC CNKXK EUA'XK MUOTM.ZNOY SKYYGMK CORR YKRL-JKYZXAIZ OT LOBK YKIUTJY.


"


Let's say that Ethan knows the key as 6. Let's decrypt the message...





Bruteforcing Caesar Cipher


We all know that this type of encryption won't work on today's standard. Thus this can be easily decrypted, in matters of attempt, without the attacker knowing the value of the key. Let's go bad and 'bruteforcely' decrypt the 2nd example from above.




Reverse engineering the mathematical algortihm mentioned above,I have managed to decrypt the code on the 17th attempt, with 25 total attempts.


<krontek>halt



66 views0 comments

コメント


LET'S TAKE IT TO THE NEXT LEVEL!

bottom of page