xcoder
Member in Training
Posts: 56
|
Post by xcoder on Jan 29, 2021 21:16:38 GMT
Print "##############################################"
msg$ = "" 'empty input string for testing PRNG key stream
code$ = "AAE1E2E3FF" 'hex$
for i = 1 to len(code$)step 2
chunk$ = mid$(code$,i,2)
print chunk$,
byte = hexDec(chunk$)
print byte
key$ = key$ + chr$(byte)
next i
call KSA key$
print
RC4$ = PRGA$(msg$)
'print RC4$
print:print
print "End of Code"
End
sub KSA key$
dim S(256)
dim K(256)
i = 0
j = 0
for i=0 to 255
S(i)=i
next i
for i = 0 to 255
K(i)= asc(mid$(key$,i mod len(key$)+1))
next i
for i = 0 to 255
j = (j+ S(i)+ K(i))mod 256
temp = S(i)
S(i)= S(j)
S(j)= temp
next i
end sub
'-------------------------------------------------
function PRGA$(msg$)
j = 0
x = 0
do while 1 'to generate keystream/no msg$
x = x + 1
if x > 2^10 then exit do 'for testing
byte = asc(mid$(msg$,x,1)) 'equal zero because no msg$
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
k = (S(i) + S(j))mod 256
cipher = byte xor k
ascii$ = ascii$ + chr$(cipher)
loop
' print ascii$
' PRGA$ = ascii$
PRGA$ = text2Hex$(ascii$)
end function
function text2Hex$(txt$)
for i = 1 to len(txt$)
hex$ = dechex$(asc(mid$(txt$,i,1)))
fullHex$ = fullHex$ + right$("0" + hex$, 2)+ space$(2)
next i
ctr = 0
for x = 1 to len(fullHex$) step 64 '16 * 32 *32
chunk$ = mid$(fullHex$,x,64)
print ctr,chunk$
ctr = ctr + 1
next x
end function
|
|