xcoder
Member in Training
Posts: 56
|
Post by xcoder on Apr 7, 2023 7:48:57 GMT
'Text Encryption ARC4 stream cipher 'author = xcoder ' This version allows use of plain text pass words as the "Key" ^^^^^^^^^^^^ ' Just paste text into the texteditor and press encrypt button 'Uses hexidecimal Text Format that is Word Processor and Email compatible nomainwin global key$, key2$ WindowWidth = 600 : WindowHeight = 400 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) texteditor #main.text, 200, 20, 360, 320 button #main.enc, "Encrypt", [encrypt], ul, 55, 155, 110, 25 button #main.dec, "Decrypt", [decrypt], ul, 55, 195, 110, 25 button #main.clearKey , "Clear Key", [clearKey], ul, 30, 75, 70, 20 button #main.dec , "Clear Text", [clearText], ul, 110, 75, 70, 20 button #main.refresh , "Delete Encrypted File", [refresh], ul, 40, 240, 135, 25 button #main.copytext , "Copy Text", [copytext], ul, 75, 105, 60, 25 textbox #main.key, 30, 45, 150, 20 statictext #main.editor, "Type or Paste Text Here", 335, 5, 190, 15 statictext #main.encKey, "Encryption Key (Hex Characters)", 20, 30, 170, 15 Open "ARC4 Type Stream Encryptor " for window as #main #main "trapclose [quit]"
key$ = "9e3779b9a1b2c3d4" ''' default key if none entered prompt "Enter hexcidecimal Key"; key$ '''any number of hex characters #main.key key$ #main.text "!autoresize" if fileExists(DefaultDir$, "textEditor") then open "textEditor" for input as #1 #main.text , text$ 'read from textEditor close #1 #main.text "!origin 0 0" 'reset cursor end if
wait [encrypt] if cript = 1 then [decrypt] #main.key "!contents? key$"
if key$ = "" then [advise] #main.text "!contents? text$" ' read from textEditor text$ = trim$(text$) call keyPass '''^^^^^^^^^^^^^ modified call KSA alpha$ = txPRGA$(text$) '***** encrypt #main.text "!cls" cript = 1 #main.text alpha$ 'write to textEditor open "textEditor" for output as #1 #1 alpha$ close #1 #main.text "!origin 0 0" 'reset cursor
wait [decrypt] #main.key "!contents? key$" if key$ = "" then [advise] #main.text "!contents? text$" 'read from textEditor text$ = trim$(text$) call keyPass '''^^^^^^ modified call KSA bravo$ = hex2Text$(text$) '***** decrypt #main.text "!cls" cript = 0 #main.text bravo$ 'write to textEditor open "textEditor"for output as #1 #1 bravo$ close #1 #main.text "!origin 0 0" 'reset cursor
wait [clearKey] #main.key "" wait [clearText] #main.text "!cls" wait [refresh] if fileExists(DefaultDir$, "textEditor") then kill DefaultDir$;"\textEditor" #main.text "!cls" wait [copytext] #main.text "!selectall" #main.text "!copy" wait [quit] close #main End [advise] notice "Key is required" close #main End
print "------------------------------------------------------------------------------------------------------------"
'function for checking file existence function fileExists(path$, filename$) dim info$(0, 0) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
sub keyPass key2$ = key$ print key2$ end sub
sub KSA '''''key expansion ^^^^^^^^^^^ 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$(key2$,i mod len(key2$)+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
print "############## Encryption Functions ##################"
function txPRGA$(inString$) '''''psuedo random byte generator i = 0 j = 0 for x = 1 to len(inString$) i = (i + 1) mod 256 '******** 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 ''' xor text bytes with St (psuedo random bytes) 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 "############# Decryption functions ###############"
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$) '''^^^^psuedo random byte generator i = 0 j = 0 for x = 1 to len(inString$) i = (i + 1) mod 256 '********** 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 ''' xor text bytes with St (psuedo random bytes) char$ = char$ + chr$(k) next x rxPRGA$ = char$ end function
|
|