Ooops
November 28, 2020, 11:36:55 AM

Author Topic: [bb] Vernam-Cipher | Encryption & Decryption by ozzi789 [ 1+ years ago ]  (Read 1054 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Vernam-Cipher | Encryption & Decryption
Author : ozzi789
Posted : 1+ years ago

Description : 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


Code :
Code: BlitzBasic
  1. ;ozzi789 - 30.01.2012
  2. original_string$="Vernam ist toll"
  3. Print "Original String: "+original_string$
  4.  
  5. encrypted_string$= vernam_enc(original_string$,"secret1")
  6. Print "Encrypted String: "+encrypted_string$
  7.  
  8. decrypted_string$=vernam_dec(encrypted_string$,"secret1")
  9. If original_string$=decrypted_string$
  10.         Print "Decrypted String: "+decrypted_string$
  11. Else
  12.         Print "This should not happen :'("
  13. EndIf
  14.  
  15.  
  16. Function vernam_enc$(strng$,key$)
  17.         len_strng=Len(strng$)
  18.         len_key=Len(key$)
  19.        
  20.         key_index=1
  21.         For x=1 To len_strng
  22.                 current_strng$=Mid(strng$,x,1)
  23.                 current_key$=Mid(key$,key_index,1)
  24.                 new_strng$=new_strng$+Chr(Asc(current_strng$)+Asc(current_key$))
  25.                 key_index=(x Mod len_key)+1
  26.         Next   
  27.         Return new_strng$
  28. End Function
  29.  
  30. Function vernam_dec$(strng$,key$)
  31.         len_strng=Len(strng$)
  32.         len_key=Len(key$)
  33.        
  34.         key_index=1
  35.         For x=1 To len_strng
  36.                 current_strng$=Mid(strng$,x,1)
  37.                 current_key$=Mid(key$,key_index,1)
  38.                 new_strng$=new_strng$+Chr(Asc(current_strng$)-Asc(current_key$))
  39.                 key_index=(x Mod len_key)+1
  40.         Next   
  41.         Return new_strng$
  42. End Function


Comments :


Guy Fawkes(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 1+ years ago)

 I love encryption stuff, thanks for posting 'Vernam-Cipher'.


Guy Fawkes(Posted 1+ years ago)

 Can someone show an example or site that has this exact function only in PHP, javascript, jquery, or JSON?thanks!


virtlands(Posted 1+ years ago)

 The Vernam Cipher {Crypto Museum}     -- <font class="tiny"> <a href="http://tinyurl.com/kzo37zx" target="_blank">http://tinyurl.com/kzo37zx[/url] </font> Inside the world of Ciphers {in Java} -- <font class="tiny"> <a href="http://tinyurl.com/m3wz2dw" target="_blank">http://tinyurl.com/m3wz2dw[/url] </font> Javascript - simple vernam cipher     -- <font class="tiny"> <a href="http://tinyurl.com/nm47u22" target="_blank">http://tinyurl.com/nm47u22[/url] </font> GitHub Gist Vernam Cipher in JS       -- <font class="tiny"> <a href="http://tinyurl.com/nast2jb" target="_blank">http://tinyurl.com/nast2jb[/url] </font> Vernam Cipher in C# {CodeProject }    -- <font class="tiny"> <a href="http://tinyurl.com/l3cbyrf" target="_blank">http://tinyurl.com/l3cbyrf[/url] </font> Vernam Cipher in Java {dream in code} -- <font class="tiny"> <a href="http://tinyurl.com/n2zzz56" target="_blank">http://tinyurl.com/n2zzz56[/url] </font>


zoqfotpik(Posted 1+ years ago)

 This is essentially a one-time pad and thus is secure.  But he says this:<div class="quote"> My functions repeat the keyword/password if its shorter than the string you are manipulating </div>If it does that, it is instantly zero security (due to differential cryptanalysis) so shouldn't be used for anything serious with keys shorter than the message.  The problem with sufficiently long keys becomes key exchange.


Guy Fawkes(Posted 1+ years ago)

 Then tell us, oh wise one. How would you fix this script then?


Matty(Posted 1+ years ago)

 Use a key as long as the message....


dna(Posted 4 months ago)

 When you use:
Code: [Select]
VERNAM_DEC$(E$,Left$(K$,Rand(1,Len(K$))))You get a partial answer to the original text. I did it this way to see if this could be a weak spot in the cypher.Is it?


Guy Fawkes(Posted 4 months ago)

 Not if you do it right.~GF [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal