One-time pad: Difference between revisions

From Rosetta Code
Content added Content deleted
m (support for management)
Line 9: Line 9:
* optional: management of One-time pads: list, mark as used, delete, etc.
* optional: management of One-time pads: list, mark as used, delete, etc.
: Somehow, the users needs to keep track which pad to use for which partner.
: Somehow, the users needs to keep track which pad to use for which partner.

To support the management of pad-files:
* such files have a file-extension ".otp"
* lines starting with "#" may contain arbitary meta-data (i.e. comments)




For example, here is the data from [http://upload.wikimedia.org/wikipedia/commons/6/60/One-time_pad.svg Wikipedia]:
For example, here is the data from [http://upload.wikimedia.org/wikipedia/commons/6/60/One-time_pad.svg Wikipedia]:
<pre>
<pre>
# Example data - Wikipedia - 2014-11-13
ZDXWWW EJKAWO FECIFE WSNZIP PXPKIY URMZHI JZTLBC YLGDYJ
ZDXWWW EJKAWO FECIFE WSNZIP PXPKIY URMZHI JZTLBC YLGDYJ
HTSVTV RRYYEG EXNCGA GGQVRF FHZCIB EWLGGR BZXQDQ DGGIAK
HTSVTV RRYYEG EXNCGA GGQVRF FHZCIB EWLGGR BZXQDQ DGGIAK
Line 27: Line 32:
Get true random numbers, and turn them into strings.
Get true random numbers, and turn them into strings.


From [http://wiki.tcl.tk/29163 Tcl'ers wiki] "Cryptographically secure random numbers using /dev/urandom"
From Tcl'ers wiki [http://wiki.tcl.tk/29163 Cryptographically secure random numbers using /dev/urandom]


<lang Tcl>puts "# True random chars for one-time pad"
<lang Tcl>puts "# True random chars for one-time pad"
Line 57: Line 62:
: IDEVVW KCTMY KLKLID DSGKIV WHMOX LIEYWF MCIECW OUQVIV.
: IDEVVW KCTMY KLKLID DSGKIV WHMOX LIEYWF MCIECW OUQVIV.
</pre>
</pre>

Todo: write strings to file
...


===Part 2===
===Part 2===
Encryption / Decryption

See Tcl'ers wiki:
[http://wiki.tcl.tk/2884 vignere]
[http://wiki.tcl.tk/23095 Vigenere]
...


===Part 3===
Management
* list padfiles in directory
* list block between "comment"-lines in padfile
...
...

Revision as of 13:43, 18 November 2014

One-time pad is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Implement a One-time pad

Sub-Tasks
  • generate the data for a One-time pad (user needs to specify a filename and length)
The important part is to get "true random" numbers, e.g. from /dev/random
  • encryption / decryption ( basically the same operation, much like Rot-13 )
For this step, much of Vigenère cipher could be reused,
with the key to be read from the file containing the One-time pad.
  • optional: management of One-time pads: list, mark as used, delete, etc.
Somehow, the users needs to keep track which pad to use for which partner.

To support the management of pad-files:

  • such files have a file-extension ".otp"
  • lines starting with "#" may contain arbitary meta-data (i.e. comments)


For example, here is the data from Wikipedia:

# Example data - Wikipedia - 2014-11-13
ZDXWWW EJKAWO FECIFE WSNZIP PXPKIY URMZHI JZTLBC YLGDYJ 
HTSVTV RRYYEG EXNCGA GGQVRF FHZCIB EWLGGR BZXQDQ DGGIAK 
YHJYEQ TDLCQT HZBSIZ IRZDYS RBYJFZ AIRCWI UCVXTW YKPQMK 
CKHVEX VXYVCS WOGAAZ OUVVON GCNEVR LMBLYB SBDCDC PCGVJX 
QXAUIP PXZQIJ JIUWYH COVWMJ UZOJHL DWHPER UBSRUJ HGAAPR 
CRWVHI FRNTQW AJVWRT ACAKRD OZKIIB VIQGBK IJCWHF GTTSSE 
EXFIPJ KICASQ IOUQTP ZSGXGH YTYCTI BAZSTN JKMFXI RERYWE 

Tcl

Part 1

Get true random numbers, and turn them into strings.

From Tcl'ers wiki Cryptographically secure random numbers using /dev/urandom

<lang Tcl>puts "# True random chars for one-time pad"

proc randInt { min max } {

   set randDev [open /dev/urandom rb]
   set random [read $randDev 8]
   binary scan $random H16 random
   set random [expr {([scan $random %x] % (($max-$min) + 1) + $min)}]
   close $randDev
   return $random

}

set alfa "ABCDEFGHIJKLMNOPQRSTUVWXYZ" set len 48 set rs "" for {set i 0} {$i < $len} {incr i} {

 if { [expr {$i % 6} ] == 0} { append rs " " }
 set r [randInt 1 26]
 set char [string index $alfa $r]
 append rs $char

} puts ":$rs." </lang>

Output:
# True random chars for one-time pad
: IDEVVW KCTMY KLKLID DSGKIV WHMOX LIEYWF MCIECW OUQVIV.

Todo: write strings to file ...

Part 2

Encryption / Decryption

See Tcl'ers wiki: vignere Vigenere ...


Part 3

Management

  • list padfiles in directory
  • list block between "comment"-lines in padfile

...