[ create a new paste ] login | about

Link: http://codepad.org/fFmsqWJQ    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Dec 29:
; one-time pad

(define-syntax for
  (syntax-rules ()
    ((for (var first past step) body ...)
      (let ((ge? (if (< first past) >= <=)))
        (do ((var first (+ var step)))
            ((ge? var past))
          body ...)))
    ((for (var first past) body ...)
      (let* ((f first) (p past) (s (if (< first past) 1 -1)))
        (for (var f p s) body ...)))
    ((for (var past) body ...)
      (let* ((p past)) (for (var 0 p) body ...)))))
(define (undigits ds . args)
  (let ((b (if (null? args) 10 (car args))))
    (let loop ((ds ds) (n 0))
      (if (null? ds) n
          (loop (cdr ds) (+ (* n b) (car ds)))))))

(define *n*
  (let ((p 18446744073709551359)
        (q 18446744073709551427))
    (* p q)))

(define *s* 20131217) ; rip mom

(define (bbs)
  (set! *s* (modulo (* *s* *s*) *n*))
  (modulo *s* 2))

(define (rand-letter)
  (let loop ((i 26) (ds (list)))
    (if (positive? i)
        (loop (- i 1) (cons (bbs) ds))
        (let ((m (undigits ds 2)))
          (if (< 67108860 m)
              (rand-letter)
              (integer->char
                (+ (modulo m 26) 65)))))))

(define (one-time-pad rows cols)
  (for (r 0 rows)
    (for (c 0 cols)
      (for (j 0 5)
        (display (rand-letter)))
      (display #\space))
    (newline)))

(one-time-pad 40 6)


Output:
BSDIV OFTPJ HRKAC BPDIR JTPLH HGXEV 
YSARW PMCVO OPICU WHABS QJSUF QNZDD 
JUNWP HYILU AIZDM VARNQ ZFSUX ELVFE 
ILZOV CZQCH LGPJD VNKEV YOUZA YHTAH 
RJPFX OLNUW UFSXH XTKCL GEYMV VSSNU 
VHVSY ZUBUC XVKRY YHFEF XYMSZ JRIFU 
RTIYH SUSQG APQDW VHRDC XIYRF XZFTJ 
UFRUF UIAKW HIJQS HCIYP GUGOE FTZAG 
XZSVM DDRHV MGBOY CFSKX LHCCM LADMP 
NRAJN QMZMX PKOBY FMAZO GDFQX CBPBO 
WQDCQ WDLYQ CWAHM NGQHC KCNPI KKFBN 
KHJRR YEQCY ZBWDP FMTNJ FYEHX QIRPP 
YDLKJ ROMEK ZOXVV PPFOI GWDGS FPJKZ 
AYIMB MLISK IKDTV IMWZE GZJUL CVNKF 
YWNPM GWRHR YEQGY ZWCNT QNOEV ZYBHT 
ONPWL EJYSH XFRQO XYSLG IRIXU MPKAO 
UJTXP RNJBU ATDDB LHCFB EQWZJ MTVMA 
DYVRM XBXYG HAGQM BDXOW QSXBR UDJQD 
AGDJW QQGPJ YHFAI JUPMJ XKQJJ WVHBI 
GSBNT FCTXW MTUBZ WGCXL TMIPA WUKMF 
RMZTM GYKPJ QOYZE MJTOL MXXRI NDNBT 
KXTOI YQONE VUMPE DWMFX DQPYB IPTVW 
OJZGA JIRMU HFTZZ HYSAD QPDIM EGVAY 
ADYPT NMEHD VRYCI GNZNV XWOTV OOLCS 
KWWJN CYKPJ LKOVS DMAFL DMJXE JVTZB 
LSPFX LSWMU NYEDN WONTP QETKW SULQA 
WEQWE PLEHN NZTVD MGJER KKKIM DITTV 
MDOUR QKYTB QWVMJ IXUST DZUAV RCDDT 
JSXDY QHDSZ RFIDL BCVRJ UOEGZ JDESI 
MDDMK TJQNW ZKZBY VOSHY YPGEH YEJWQ 
JHYWM QFNQR HNWYV QQVYY PCKUT LQASO 
BKIYY MSCWN JKWDL EKGND CBQUM VKQGZ 
MEPOB HNRVF OJHIN NWHRC RFIJU SDNHZ 
CHBFW INFEF VIAPM KFBQB YOVIF NQQNW 
DSOQA CWMMO SXELL WSCLU RDVCJ YFUXN 
UBXJM AZSCS FYZIK MRTRN BNAYM QYMZP 
TNUZB IWYZU IGTQA GUTUR LHNCN UUDCT 
XJBCS HIRXF ZIZSQ BHGHF WOOUR IUVNI 
KYBVV LUTBR MHDHS BSYYU LQJDN RBHNN 
KJLGU NGVES EFVEB KASJM DYTTV HLNSZ 


Create a new paste based on this one


Comments: