The Laws of Cryptography:
Generating a One-time Pad

by Neal R. Wagner

Here is a Java program which, when executed, generates a unique Postscript file that will print a one-time pad:

```// Pad.java: generate Postscript code to print a one-time pad
import java.text.DecimalFormat;

public class Pad {
static DecimalFormat twoDigits = new DecimalFormat("00");
// main function   twoDigits.format()
static char[] let = {'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
static int xCoord = 0, yCoord = 0;
static int lineCount = 0;

public static void main (String[] args) {
System.out.println("/Courier-Bold findfont 14 scalefont setfont");
for (int i = 0; i < 20; i++) {
System.out.println("0 " + yCoord + " moveto");
System.out.print("(" + twoDigits.format(lineCount) + " ");
for (int j = 0; j < 50; j++) {
System.out.print(oneLet());
if (j%5  == 4) System.out.print(" ");
if (j%10 == 9) System.out.print(" ");
}
System.out.println(") show");
yCoord -= 15;
if (lineCount == 9) System.out.println();
if (lineCount%5 == 4) yCoord -= 15;
lineCount++;
}
System.out.println("}def");
System.out.println("gsave 30 750 translate onepad grestore");
System.out.println("gsave 30 360 translate onepad grestore");
System.out.println("10 390 moveto");
System.out.print  ("(============t=e=a=r===h=e=r=e=======");
System.out.println("=======t=e=a=r===h=e=r=e=============) show");
System.out.println("showpage");
} // end of main

private static char oneLet() {
return let[(int)(Math.random()*26)];
}
}
```

Here is typical output of the program, a Postscript file. (It will have different random characters in it each time it is generated by executing the Java program.)

```%!PS-Adobe-2.0
/Courier-Bold findfont 14 scalefont setfont
0 0 moveto
(00 XLCWT HZZTC  HUTXA GQAUN  FXCUI QFBVW  DKAPS SXKHK  XBLLP LTHFO  ) show
0 -15 moveto
(01 XUMVS SRMGB  SPSDI UAFYO  CQYHQ CYSHU  UCATL HLDKZ  XWFGR LRMOL  ) show
0 -30 moveto
(02 DXCBR FMARY  MOLUR CDJVT  MACWT IRFVP  DZBBY ZTFZG  HCUUL YYKPF  ) show
0 -45 moveto
(03 QSWIH HNWRC  FQQHM ZEKJP  URILH THNSY  TLMWA CWYJV  AWOWY IAELZ  ) show
0 -60 moveto
(04 KJKJE NGKDD  NYMYP NRNHK  KRIOX TIFSY  TGYRS HZLTQ  MCEBA YRBTU  ) show
0 -90 moveto
(05 CZLFW HYSTM  YGDBN GVAZE  RFCQY YFHLC  OGLHY OEBNB  QDQIS EHIBB  ) show
0 -105 moveto
(06 ZIWQC TYERS  UZGSS EGOVX  KGXJV AONYN  HXZCR RLUSN  SXXBR EJKQH  ) show
0 -120 moveto
(07 OIJMF LCZHA  CGMYK LPLMU  CIMHZ WBVHD  JXNZJ CJLSN  PJVFL HENCU  ) show
0 -135 moveto
(08 ZOHEW JRWPC  BHFRZ MEYBW  SHFPQ DYQFH  ARDQI UAHOC  OAQKR LZPBF  ) show
0 -150 moveto
(09 YAKMA YJVYY  HSAZB SMILL  WMHAJ KMYNO  YHTXY GIISP  CVYQC OMCIP  ) show

0 -180 moveto
(10 NPNVY VACCU  YWOFW GLHTO  TOUPS LRLOV  SZWBL WYNJO  NOHCZ SZSZS  ) show
0 -195 moveto
(11 UBSOT FSRSM  BLDEC IXQDZ  STPAJ YOMBO  CGIAD HUTHZ  JAURL MCRNY  ) show
0 -210 moveto
(12 VPVSF RSXSQ  UMOMQ KGJCY  BIJXE QQDFF  BHOGG RCTXO  KJRMC QINMZ  ) show
0 -225 moveto
(13 BEFIF UIEVB  UGWZJ ENOLD  CTNBD JWKCR  JTIKX DIRYK  WUZPH HGTAU  ) show
0 -240 moveto
(14 IPAOV IHDQA  VENRD RCFLR  ZRTOW NIHWY  TGWQX WWRHY  QSBMD IWSMQ  ) show
0 -270 moveto
(15 IYCMO WUPZM  OFPJW ZUUDB  QZIHP RNQTT  UMTDS ANATC  DANSQ YUYGT  ) show
0 -285 moveto
(16 XYCZU AKGWK  ZPEMS TAQLE  KKIYG UANUN  ZNTPP NZVTX  KPZCD BUYMT  ) show
0 -300 moveto
(17 DKZSJ SIMPP  EAFSS KNBOO  OATKY UKMYP  NZPGS ELIHP  JWWAQ ILRBV  ) show
0 -315 moveto
(18 RSBTM XROFG  MPGJT HIEIZ  XRSNN FIRYQ  AFGGR BYVQY  RXCFV CBBUO  ) show
0 -330 moveto
(19 ZTRPC HHVJO  BPXHL UGNLP  CLVUN DTGZI  NTCBM EDBRG  ZQUOY PFZHO  ) show
}def
gsave 30 750 translate onepad grestore
gsave 30 360 translate onepad grestore
10 390 moveto
(============t=e=a=r===h=e=r=e==============t=e=a=r===h=e=r=e=============) show
showpage
```

Finally, a link to the actual postscript file is here: In Postscript, In PDF.

Revision date: 2001-12-28. (Please use ISO 8601, the International Standard.)