xcoder
Member in Training
Posts: 56
|
Post by xcoder on Jan 30, 2021 20:55:54 GMT
Print "#################################"
'Same program code for encrypltion and decryption
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
input "File to read: ";file$
input "File to write: ";file2$
open file$ for input as #1
open file2$ for output as #2
msg$ = input$(#1,lof(#1))
a$ = PRGA$(msg$,key$)
print #2,a$;
close #1
close #2
for i = 1 to 6
print space$(i);"Processing"
next
print "------------------End of File ---------------------"
print:print
print "End of Code"
End
function PRGA$(msg$,key$)
dim S(256)
dim K(256)
i = 0
j = 0
for i=0 to 255
S(i)= i
next i
print ""
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
'-------------------------------------------------
i = 0
j = 0
for x = 1 to len(msg$)
byte = asc(mid$(msg$,x,1)) 'cannot use i nor j
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)
next x
PRGA$ = ascii$
end function
|
|