> ...from a project I'm working on...
Final version, unless someone spots something out of place.
windows ---------------------------------------------------
@echo off
:: one time pad generator...
::
::
https://en.wikipedia.org/wiki/One-time_pad
::
:: 'Anyone who attempts to generate random numbers
:: by deterministic means is, of course, living
:: in a state of sin' ~ John von Neumann
::
:: pad serialization...
::
:: .----------------------> year
:: | .---------------> month
:: | | .----------> day
:: [xxxx] [xx] [xx] [xxx]-> random 3 digit number
::
:: character count...
::
:: per cell: 005
:: per row: 025
:: per column: 100
:: per block: 500
::
:: entropy avg. (10 iterations)...
::
:: numeric: 3.31396
:: alphabet: 4.66583
if [%~1]==[] goto :syntax
if %~1==/n (
set d=0987654321
set /a n=10
) else if %~1==/a (
set d=ZYXWVUTSRQPONMLKJIHGFEDCBA
set /a n=26
) else (goto :syntax)
set /a e=(%random%*999)+999
set s=%date:~10,4%%date:~4,2%%date:~7,2%%e:~1,3%
echo. & echo %s% destroy after use & echo.
setlocal enabledelayedexpansion
for /l %%x in (1,1,20) do (
for /l %%y in (1,1,5) do set c%%y=
for /l %%z in (1,1,5) do (
for /l %%p in (1,1,5) do (
set /a r=!random!*%n%/32768
call set c%%p=!c%%p!%%d:~!r!,1%%
)
)
echo !c1! !c2! !c3! !c4! !c5!
)
endlocal
exit /b
:syntax
cls
echo. & echo one time pad generator - Michael Sanders 2017
echo. & echo syntax: %~nx0 [/n^|/a] & echo.
echo /n numeric pad & echo /a alphabetic pad
unix ------------------------------------------------------
#!/bin/sh
<<DOC
one time pad generator...
https://en.wikipedia.org/wiki/One-time_pad
'Anyone who attempts to generate random numbers
by deterministic means is, of course, living
in a state of sin' ~ John von Neumann
pad serialization...
.----------------------> year
| .---------------> month
| | .----------> day
[xxxx] [xx] [xx] [xxx]-> random 3 digit number
character count...
per cell: 005
per row: 025
per column: 100
per block: 500
entropy avg. (10 iterations)...
numeric: 3.31396
alphabet: 4.66583
DOC
syntax() {
clear
cat <<MSG
one time pad generator - Michael Sanders 2017
syntax: otp.sh [-n|-a]
-n numeric pad
-a alphabetic pad
MSG
exit 1
}
case $1 in
-n|-N) v=digit;;
-a|-A) v=upper;;
*) syntax;;
esac
r=$(strings /dev/urandom | tr -cd "[:$v:]" | fold -w 5 | head -n 100)
cat <<OTP
$(date +%Y%m%d)$(echo $r | cut -c 1-3) destroy after use
$(echo "$r" | awk '{printf("%s ", $0); if (NR % 5 == 0) printf("\n")}')
OTP
exit 0
# eof