Post by xcoder on Nov 25, 2022 14:24:27 GMT
ARC4 Stream Cipher Hex Format
Email Compatible"
print "####################################"
print " ARC4 Stream Cipher Hex Format"
print " Email Compatable"
print:print
global key$ '***************
print space$(10);" Select an Option: "
print space$(10);" Select (1) for Encrypt"
print space$(10);" Select (2) for Decrypt"
print space$(10);" Select (3) to Quit"
input "Enter your choice: ";var
select case var
case 1
call readWriteFile
case 2
call readWriteNext
case 3
call Quit
case else
call invalid
end select
print:print
wait
End
sub KSA
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
sub hexKey$ keybd$
print "Hex" + space$(5) + "Decimal"
for i = 1 to len(keybd$)step 2
chunk$ = mid$(keybd$,i,2)
byte = hexDec(chunk$)
if byte = 0 then
cls
call invalid
end if
key$ = key$ + chr$(byte)
print chunk$, byte
next i
end sub
sub delay
timer 2000, [timertest]
wait
[timertest]
timer 0
end sub
sub readWriteFile
input "Enter hex key code: ";keybd$
call hexKey$ keybd$
print key$
call KSA
call delay
filedialog "Open text file", "*.txt", infile$
print "File chosen is ";infile$
filedialog "Save As...", "*.txt", outfile$
print "File chosen is ";outfile$
open infile$ for input as #r
open outfile$ for output as #w
while eof(#r) = 0
input #r, text$
alpha$ = txPRGA$(text$)
print #w, alpha$
wend
close #r
close #w
for i = 0 to 7
print space$(i);"Encrypting"
next i
print ""
print "Process Completed"
end sub
function txPRGA$(inString$)
i = 0 :j = 0
for x = 1 to len(inString$)
i = i + 1
byte = asc(mid$(inString$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
St = (S(i) + S(j))mod 256
k = byte xor St
char$ = char$ + chr$(k)
next x
txPRGA$ = text2Hex$(char$)
end function
function text2Hex$(cipher$)
for i = 1 to len(cipher$) 'encrypted text
byte = asc(mid$(cipher$,i,1)) 'encrypted ascii
hex$ = decHex$(byte)
hex$ = right$("0" + hex$,2)
max$ = max$ + hex$ 'encrypted hex
next i
text2Hex$ = max$
end function
print "-----------------------------------------------"
sub readWriteNext
input "Enter key code: ";keybd$
call hexKey$ keybd$
print key$
call KSA
call delay
filedialog "Open text file", "*.txt", infile$
print "File chosen is ";infile$
filedialog "Save As...", "*.txt", outfile$
print "File chosen is ";outfile$
open infile$ for input as #r
open outfile$ for output as #w
while eof(#r) = 0
input #r, text$
alpha$ = hex2Text$(text$)
print #w, alpha$
wend
close #r
close #w
for i = 0 to 7
print space$(i);"Decrypting"
next i
print ""
print "Process Completed"
end sub
function hex2Text$(hex$)
for i = 1 to len(hex$)step 2 'encrypted hex
chunk$ = mid$(hex$,i,2)
byte = hexDec(chunk$) 'encrypted ascii
text$ = text$ + chr$(byte) 'encrypted text
next i
hex2Text$= rxPRGA$(text$)
end function
function rxPRGA$(inString$)
i = 0 :j = 0
for x = 1 to len(inString$)
i = i + 1
byte = asc(mid$(inString$,x,1))
j = (j + S(i))mod 256
temp = S(i)
S(i) = S(j)
S(j) = temp
St = (S(i) + S(j))mod 256
k = byte xor St
char$ = char$ + chr$(k)
next x
rxPRGA$ = char$
end function
'--------------------------------------------------------------------------------------------------------
sub Quit
print "quiting application"
print "Goodbye!"
wait
End
end sub
sub invalid
print "invalid input. Select options from menu"
print "Use only hex characters for key"
print "Goodbye!"
wait
End
end sub