S- - 14


f i%, bdes(), xdes()

FOR j% = 1 TO 32

ades(j%) = (bdes(j% + 32) + xdes(j%)) MOD 2

NEXT j%

FOR j% = 33 TO 64

ades(j%) = bdes(j% - 32)

18.4

NEXT j%

NEXT i%

transpose ades(), FinalTr(), 64

btos ades(), temp$

desalg$ = temp$

END FUNCTION

SUB f (i%, a() AS INTEGER, x() AS INTEGER)

h% = i%: letbe EF(), a(), 64

transpose EF(), etr(), 48

letbe ikeyf(), P2(), 64

transpose ikeyf(), KeyTr2(), 48

FOR j% = 1 TO rots(h%)

mrotate P2()

NEXT j%

FOR j% = 1 TO 48

yf(j%) = (EF(j%) + ikeyf(j%)) MOD 2

NEXT j%

FOR k% = 1 TO 8

k6% = 6 * k%: k4% = 4 * k%

r% = (32 * yf(k6% - 5)) + (16 * yf(k6%)) + (8 * yf(k6% - 4)) + (4 * yf(k6% - 3)) + (2 * yf(k6% - 2)) + yf(k6% - 1) + 1

x(k4% - 3) = (s(k%, r%) \ 8) MOD 2: x(k4% - 2) = (s(k%, r%) \ 4) MOD 2

x(k4% - 1) = (s(k%, r%) \ 2) MOD 2: x(k4%) = s(k%, r%) MOD 2

NEXT k%

transpose x(), ptr(), 32

END SUB

SUB init (x() AS INTEGER, n%)

FOR i% = 1 TO n%

READ x(i%)

NEXT i%

END SUB

SUB letbe (target() AS INTEGER, source() AS INTEGER, last%)

FOR il% = 1 TO last%

target(il%) = source(il%)

NEXT il%

END SUB

18.4

FUNCTION MYBIN$ (n%)

STS$ = ""

p% = n%

FOR i% = 1 TO 8

IF (p% MOD 2) THEN

ST$ = "1" + ST$

ELSE

ST$ = "0" + ST$

END IF

p% = p% \ 2

NEXT i%

MYBIN$ = ST$

END FUNCTION

SUB mrotate (keyr() AS INTEGER)

letbe XR(), keyr(), 56

FOR ir% = 56 TO 2 STEP -1

XR(ir%) = XR(ir% - 1)

NEXT ir%

XR(1) = keyr(28): XR(29) = keyr(56)

letbe keyr(), XR(), 56

END SUB

SUB sboxinit (b() AS INTEGER)

RESTORE sboxesl

FOR i% = 1 TO 8

FOR j% = 1 TO 64

READ b(i%, j%)

NEXT j%

NEXT i%

END SUB

SUB stob (a$, mbits() AS INTEGER)

FOR i% = 1 TO 8

b$ = MYBIN$(ASC(MID$(a$, i%, 1)))

FOR j% = 1 TO 8

mbits(((i% - 1) * 8) + j%) = ASC(MID$(b$, j%, 1)) - 48