Post by xcoder on Feb 2, 2021 20:28:00 GMT
Print "##############################################"
global key$
code$ = "AAFFE0E1E2" 'key in hex$ format
for i = 1 to len(code$)step 2
chunk$ = mid$(code$,i,2)
byte = hexDec(chunk$)
char$ = chr$(byte)
key$ = key$ + chr$(byte)
next i
print " ARC4 Stream Cipher with Random Inital Vector"
print "Select an Option: "
print "Select (1) for Encrypt"
print "Select (2) for Decrypt"
print "Select (3) to quit"
input "Enter your choice: ";num
select case num
case 1
call Encrypt 1
case 2
call Decrypt 2
case 3
print "Goodbye!"
Stop
case else
print "Invalid input"
print "Program Terminated"
call quit
end select
print:print
print "End of Code"
End
sub Encrypt x
iv$ = iv10$()
input "File to Read: ";file$
dim info$(10,10)
if fileExists(file$) then
print file$; " exists!"
else
print file$; " doesn't exist!"
call quit
end if
open file$ for input as #1
if x = 1 then file2$ = "ENC "+file$
open file2$ for output as #2
txt$ = input$(#1,lof(#1))
print #2, Encode$(txt$,iv$);
close #1
close #2
for i = 1 to 6
print space$(i);"Encrypting"
next
print "------------completed----------------"
end sub
sub Decrypt x
input "File to Read: ";file$
dim info$(10,10)
if fileExists(file$) then
print file$; " exists!"
else
print file$; " doesn't exist!"
call quit
end if
open file$ for input as #1
if x = 2 then file2$ = "DEC "+ file$
open file2$ for output as #2
txt$ = input$(#1,lof(#1))
print #2, Decode$(txt$)
close #1
close #2
for i = 1 to 6
print space$(i);"Decrypting"
next
print " --------------completed-------------------------"
end sub
function Encode$(msg$,iv$)
print iv$ '******************
fkey$ = key$ + iv$
print fkey$ '******************
call KSA$ fkey$
out$ = PRGA$(msg$,iv$)
Encode$ = out$
end function
'============================================================
function Decode$(out$)
ivRx$ = left$(out$,10)
print ivRx$ '******************
rfkey$ = key$ + ivRx$
print rfkey$ '******************
call KSA2$ rfkey$
in$ = PRGA2$(out$)
Decode$ = in$
end function
'=============================================================
sub KSA$ fkey$
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$(fkey$,i mod len(fkey$)+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$,iv$)
i = 0
j = 0
for x = 1 to len(msg$) 'cannot use varible i or j
byte = asc(mid$(msg$,x,1))
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$ = iv$ + ascii$
end function
function iv10$()
for i = 0 to 9
x = int(rnd(1)* 256)
y$ = y$ + chr$(x)
next
iv10$ = y$
end function
'================== receive program ========================================
sub KSA2$ rfkey$
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$(rfkey$,i mod len(rfkey$)+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 PRGA2$(msg$)
text$ = mid$(msg$,11)
i = 0
j = 0
for x = 1 to len(text$) 'cannot use varible i or j
byte = asc(mid$(text$,x,1))
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
PRGA2$ = ascii$
end function
sub quit
print "Goodbye!"
stop
end sub
'-----------------------------------------------------------------
function fileExists(fullPath$)
files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
fileExists = val(info$(0, 0)) > 0
end function
function pathOnly$(fullPath$)
pathOnly$ = fullPath$
while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
wend
end function
function filenameOnly$(fullPath$)
pathLength = len(pathOnly$(fullPath$))
filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
'-------------------------------------------------------------------
global key$
code$ = "AAFFE0E1E2" 'key in hex$ format
for i = 1 to len(code$)step 2
chunk$ = mid$(code$,i,2)
byte = hexDec(chunk$)
char$ = chr$(byte)
key$ = key$ + chr$(byte)
next i
print " ARC4 Stream Cipher with Random Inital Vector"
print "Select an Option: "
print "Select (1) for Encrypt"
print "Select (2) for Decrypt"
print "Select (3) to quit"
input "Enter your choice: ";num
select case num
case 1
call Encrypt 1
case 2
call Decrypt 2
case 3
print "Goodbye!"
Stop
case else
print "Invalid input"
print "Program Terminated"
call quit
end select
print:print
print "End of Code"
End
sub Encrypt x
iv$ = iv10$()
input "File to Read: ";file$
dim info$(10,10)
if fileExists(file$) then
print file$; " exists!"
else
print file$; " doesn't exist!"
call quit
end if
open file$ for input as #1
if x = 1 then file2$ = "ENC "+file$
open file2$ for output as #2
txt$ = input$(#1,lof(#1))
print #2, Encode$(txt$,iv$);
close #1
close #2
for i = 1 to 6
print space$(i);"Encrypting"
next
print "------------completed----------------"
end sub
sub Decrypt x
input "File to Read: ";file$
dim info$(10,10)
if fileExists(file$) then
print file$; " exists!"
else
print file$; " doesn't exist!"
call quit
end if
open file$ for input as #1
if x = 2 then file2$ = "DEC "+ file$
open file2$ for output as #2
txt$ = input$(#1,lof(#1))
print #2, Decode$(txt$)
close #1
close #2
for i = 1 to 6
print space$(i);"Decrypting"
next
print " --------------completed-------------------------"
end sub
function Encode$(msg$,iv$)
print iv$ '******************
fkey$ = key$ + iv$
print fkey$ '******************
call KSA$ fkey$
out$ = PRGA$(msg$,iv$)
Encode$ = out$
end function
'============================================================
function Decode$(out$)
ivRx$ = left$(out$,10)
print ivRx$ '******************
rfkey$ = key$ + ivRx$
print rfkey$ '******************
call KSA2$ rfkey$
in$ = PRGA2$(out$)
Decode$ = in$
end function
'=============================================================
sub KSA$ fkey$
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$(fkey$,i mod len(fkey$)+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$,iv$)
i = 0
j = 0
for x = 1 to len(msg$) 'cannot use varible i or j
byte = asc(mid$(msg$,x,1))
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$ = iv$ + ascii$
end function
function iv10$()
for i = 0 to 9
x = int(rnd(1)* 256)
y$ = y$ + chr$(x)
next
iv10$ = y$
end function
'================== receive program ========================================
sub KSA2$ rfkey$
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$(rfkey$,i mod len(rfkey$)+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 PRGA2$(msg$)
text$ = mid$(msg$,11)
i = 0
j = 0
for x = 1 to len(text$) 'cannot use varible i or j
byte = asc(mid$(text$,x,1))
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
PRGA2$ = ascii$
end function
sub quit
print "Goodbye!"
stop
end sub
'-----------------------------------------------------------------
function fileExists(fullPath$)
files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
fileExists = val(info$(0, 0)) > 0
end function
function pathOnly$(fullPath$)
pathOnly$ = fullPath$
while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
wend
end function
function filenameOnly$(fullPath$)
pathLength = len(pathOnly$(fullPath$))
filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function
'-------------------------------------------------------------------