Home
Products
Community
Manuals
Contact
Login or Signup

Code archives/Algorithms/Vernam-Cipher | Encryption & Decryption

This code has been declared by its author to be Public Domain code.

Download source code

Vernam-Cipher | Encryption & Decryption by ozzi789(Posted 1+ years ago)
Those two functions let you encrypt&decrypt strings easly with a provided password.

It is pretty secure with a strong & long password.

Only ways to break the encryption is:
-Bruteforce (yeah lol)
-Frequency analysis of the letters


Note for those who know how Vernam works:
My functions repeat the keyword/password if its shorter than the string you are manipulating
;ozzi789 - 30.01.2012
original_string$="Vernam ist toll"
Print "Original String: "+original_string$

encrypted_string$= vernam_enc(original_string$,"secret1")
Print "Encrypted String: "+encrypted_string$

decrypted_string$=vernam_dec(encrypted_string$,"secret1")
If original_string$=decrypted_string$
	Print "Decrypted String: "+decrypted_string$
Else
	Print "This should not happen :'("
EndIf 


Function vernam_enc$(strng$,key$)
	len_strng=Len(strng$)
	len_key=Len(key$)
	
	key_index=1
	For x=1 To len_strng
		current_strng$=Mid(strng$,x,1)
		current_key$=Mid(key$,key_index,1)
		new_strng$=new_strng$+Chr(Asc(current_strng$)+Asc(current_key$))
		key_index=(x Mod len_key)+1
	Next	
	Return new_strng$
End Function 

Function vernam_dec$(strng$,key$)
	len_strng=Len(strng$)
	len_key=Len(key$)
	
	key_index=1
	For x=1 To len_strng
		current_strng$=Mid(strng$,x,1)
		current_key$=Mid(key$,key_index,1)
		new_strng$=new_strng$+Chr(Asc(current_strng$)-Asc(current_key$))
		key_index=(x Mod len_key)+1
	Next	
	Return new_strng$
End Function

Comments

Thundros(Posted 1+ years ago)
SWEET! I can use this to encrypt my map data even further! Thanks, Ozzi! =D


ozzi789(Posted 1+ years ago)
Glad i could help ! :)


SystemError51(Posted 1+ years ago)
I'll test this for data encryption/decryption in my game project. This is extremely interesting considering what I just read about the Vernam Cipher.

// EDIT:
It's working :)


VirtLands(Posted 3 months ago)
I love encryption stuff, thanks for posting 'Vernam-Cipher'.


Code Archives Forum