One-time pad: Difference between revisions
Content added Content deleted
Line 1: | Line 1: | ||
{{draft task}} [[Category:Encryption]] |
{{draft task}} [[Category:Encryption]] [[Category:File_handling]] |
||
Implement a [[wp:One-time pad|One-time pad]] |
Implement a [[wp:One-time pad|One-time pad]]. |
||
;Sub-Tasks: |
;Sub-Tasks: |
||
Line 34: | Line 34: | ||
Get true random numbers, and turn them into strings. |
Get true random numbers, and turn them into strings. |
||
With "randInt" 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 55: | Line 55: | ||
set char [string index $alfa $r] |
set char [string index $alfa $r] |
||
append rs $char |
append rs $char |
||
##puts "$i: $r $char" |
##puts "$i: $r $char" |
||
} |
} |
||
return $rs |
return $rs |
||
Line 63: | Line 63: | ||
set len 48 |
set len 48 |
||
set lines 4 |
set lines 4 |
||
set fn "test.otp" |
|||
set fh [open $fn w] |
|||
puts $fh "# OTP" |
|||
for {set ln 0} {$ln < $lines} {incr ln} { |
for {set ln 0} {$ln < $lines} {incr ln} { |
||
set line [randStr $len 6 $alfa] |
set line [randStr $len 6 $alfa] |
||
puts ":$line." |
##puts "$ln :$line." |
||
puts $fh $line |
|||
} |
} |
||
close $fh |
|||
</lang> |
|||
puts "# File $fn:" |
|||
set fh [open $fn] |
|||
puts [read $fh [file size $fn]] |
|||
close $fh |
|||
puts "# Done."</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
# True random chars for one-time pad |
# True random chars for one-time pad |
||
# File test.otp: |
|||
⚫ | |||
# OTP |
|||
⚫ | |||
OWCTEL SGDQEA UKEWCU PUTDEA XICBOL VVMJHD OHAXSE ZFAGDE |
|||
⚫ | |||
QHDHKQ CCJBYF CMRCMC IXXPVM IOHQDA XIDTPX FGRIJC NPDOAT |
|||
⚫ | |||
MYYQUV ZVKGDF ZLYKSX MBPLON RMQKQT QDYJVO LNKUFV DNKIQP |
|||
NQOZKU MQOWHS VOQFWL EQWBFA HZQAMG JWNHGZ QERNNV GBKQTM |
|||
⚫ | |||
# Done. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
||
Todo: write strings to file |
|||
... |
|||
===Part 2: Encrypt/Decrypt=== |
===Part 2: Encrypt/Decrypt=== |
||
Line 102: | Line 104: | ||
===Part 3: Management=== |
===Part 3: Management=== |
||
* list padfiles in directory |
* list padfiles in directory |
||
* list |
* list lines / blocks between "comment"-lines in padfile (i.e. remaining usable data) |
||
... |
... |
||
<!-- |
|||
# True random chars for one-time pad |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
--> |
Revision as of 19:23, 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)
- lines starting with "-" count as "used"
- whitespace within the otp-data is ignored
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: random strings
Get true random numbers, and turn them into strings.
With "randInt" 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
}
proc randStr { sLen grp alfa } {
set aLen [string length $alfa]; incr aLen -1 set rs "" for {set i 0} {$i < $sLen} {incr i} { if { [expr {$i % $grp} ] == 0} { append rs " " } set r [randInt 0 $aLen] set char [string index $alfa $r] append rs $char ##puts "$i: $r $char" } return $rs
}
set alfa "ABCDEFGHIJKLMNOPQRSTUVWXYZ" set len 48 set lines 4 set fn "test.otp"
set fh [open $fn w] puts $fh "# OTP" for {set ln 0} {$ln < $lines} {incr ln} {
set line [randStr $len 6 $alfa] ##puts "$ln :$line." puts $fh $line
} close $fh
puts "# File $fn:" set fh [open $fn] puts [read $fh [file size $fn]] close $fh
puts "# Done."</lang>
- Output:
# True random chars for one-time pad # File test.otp: # OTP OWCTEL SGDQEA UKEWCU PUTDEA XICBOL VVMJHD OHAXSE ZFAGDE QHDHKQ CCJBYF CMRCMC IXXPVM IOHQDA XIDTPX FGRIJC NPDOAT MYYQUV ZVKGDF ZLYKSX MBPLON RMQKQT QDYJVO LNKUFV DNKIQP NQOZKU MQOWHS VOQFWL EQWBFA HZQAMG JWNHGZ QERNNV GBKQTM # Done.
Part 2: Encrypt/Decrypt
See Tcl'ers wiki: vignere Vigenere ...
Part 3: Management
- list padfiles in directory
- list lines / blocks between "comment"-lines in padfile (i.e. remaining usable data)
...