xcoder
Member in Training
Posts: 56
|
Post by xcoder on Jan 31, 2023 10:18:21 GMT
print "###############################" dim A$(100), K1(8), K2(8), D(8), Sum(8), Sbox1(8), Sbox2(8)
print "Sbox1" data 8, 64, 16, 128, 0, 0, 0, 0 for i = 1 to 8 read alpha Sbox1(i) = alpha ''single bit flip in each byte print Sbox1(i);" "; next i print:print
data 128, 16, 64, 8, 0, 0, 0, 0 print "Sbox2" for i = 1 to 8 read alpha Sbox2(i) = alpha ''single bit flip in each byte print Sbox2(i);" "; next i print:print
global key$, two64 two64 = 2^ 64 key$ = "9e3779b9a1b2c3d4" 'hex 8 bytes (64 bits)
call subKey print "" text$ = "the quick brown fox jumps over the lazy dogs back" alpha$ = txMain$(text$) print alpha$ print "------------------------------------------" input "Press Enter to continue: ";entry$ bravo$ = rxMain$(alpha$) print bravo$ print:print
print "Finished" End
sub subKey num = hexDec(key$) alpha = leftRotate(num,1) hexKey1$ = decHex$(alpha) print hexKey1$, "subKey 1" bravo = leftRotate(num,4) hexKey2$ = decHex$(bravo) print hexKey2$, "subKey2" print "" x = 1 for i = 1 to len(hexKey1$)step 2 chunk$ = mid$(hexKey1$,i,2) byte = hexDec(chunk$) K1(x) = byte print K1(x) x = x + 1 next i print "" x = 1 for i = 1 to len(hexKey2$)step 2 chunk$ = mid$(hexKey2$,i,2) byte = hexDec(chunk$) K2(x) = byte print K2(x) x = x + 1 next i end sub
' rotates bits left n times function leftRotate(num,times) num = num mod two64 r = (num * 2^ times) mod two64 l = int(num /(2^ (64 - times))) leftRotate = r + l end function
function txMain$(text$) x = 1 for i = 1 to len(text$) step 8 chunk$ = mid$(text$,i,8) y = len(chunk$) if y < 8 then chunk$ = chunk$ + addPad$(y) A$(x) = chunk$ '********************* print A$(x), x outStr$ = outStr$ + txRound1$(chunk$) 'envoke the rounds of cipher x = x + 1 'number of text blocks next i txMain$ = outStr$ end function
function addPad$(x) 'pads the final text block if x < 8 then dif = 8 - x for i = 1 to dif pad$ = pad$ + chr$(0) next i end if addPad$ = pad$ end function
function txRound1$(in$) sideL$ = right$(in$,4) 'swap left and right halfs of data block sideR$ = left$(in$,4) perm$ = sideL$ + sideR$ for i = 1 to 4 'process index 1 to 4 of D (new right half of data block) byte = asc(mid$(perm$,i,1)) 'Feistel technique D(i) = byte Sum(i) = K1(i) xor D(i) xor Sbox1(i) 'key xor data then Sbox flips one bit char$ = char$ + chr$(Sum(i)) next i swap$ = char$ + sideR$ 'combine processed half and plain half print swap$ '################ testing Feistel technique txRound1$ = txRound2$(swap$) end function
function txRound2$(in$) sideL$ = right$(in$,4) sideR$ = left$(in$,4) perm$ = sideL$ + sideR$ for i = 1 to 4 byte = asc(mid$(perm$,i,1)) D(i) = byte Sum(i) = K2(i) xor D(i) xor Sbox2(i) char$ = char$ + chr$(Sum(i)) next i swap$ = char$ + sideR$ print swap$ '############ testing txRound2$ = swap$ print "" ' line space end function
print "-----------------------------------------------------------------"
function rxMain$(text$) x = 1 for i = 1 to len(text$) step 8 chunk$ = mid$(text$,i,8) y = len(chunk$) A$(x) = chunk$ '********************* print A$(x), x outStr$ = outStr$ + rxRound1$(chunk$) x = x + 1 'number of text blocks next i rxMain$ = outStr$ end function
function rxRound1$(in$) 'reverse function sequence sideR$ = right$(in$,4) 'unprocessed original left half for i = 1 to 4 byte = asc(mid$(in$,i,1)) D(i) = byte Sum(i) = K2(i) xor D(i) xor Sbox2(i) 'reverse key sequence char$ = char$ + chr$(Sum(i)) next i swap$ = sideR$ + char$ print swap$ '############ testing rxRound1$ = rxRound2$(swap$) 'combine unprocessed original left half end function 'and processed original right half
function rxRound2$(in$) sideR$ = right$(in$,4) for i = 1 to 4 byte = asc(mid$(in$,i,1)) D(i) = byte Sum(i) = K1(i) xor D(i) xor Sbox1(i) 'reverse key sequence char$ = char$ + chr$(Sum(i)) next i swap$ = sideR$ + char$ rxRound2$ = swap$ print "" ' line space end function
|
|
|
Post by xxgeek on Feb 1, 2023 5:06:53 GMT
Good stuff xcoder it's getting better. I like this program and would like to see it perfected so here's some input, and a little GUI helper.
It works well with short sentences, and sometimes long sentences and paragraphs, but there is something causing gibberish in the results.
One such character may be the comma. Sometimes it's ok, other times it's not. Maybe it is when it is used with a certain other character (don't know which) still trying different combos to determine exactly what causes the gibberish.
In the GUI I loaded this entire program into the texeditor. Most of it came back in the results, but as you'll see in the snippet below, near the end of the program code the gibberish starts.
' rotates bits left n times function leftRotate(num,times) num = num mod two64 r = (num * 2^ times) mod two64 l = int(num /(2^ (64 - times))) leftRotate = r + l end function
function txMñiþt`t-(ä$¹]B hp°x°mh1EZ° °p.o:pù py <?°lõ>`t-(ä$¹p;t- °8Zh hp° °p+h=>û$°mhm!4´(ä50tl|ù,¨yE hp° °ph 1p ü5&(+8ånûta Bp° °ph h9ö épt ppähõ>hc %þk´pu +8ånûth+h1ôdÀ1,$`)¹
I hope this helps you in some way to work out the details.
Here's the GUI code to help do some fast testing. I believe I've left everything else intact, and left the mainwin visible too. It will be nice to be able to encrypt files quickly, hope you can perfect this app. Thanks for posting it.
'Text Encription (in blocks) 'author = xcoder
global key$, two64 two64 = 2^ 64 dim A$(10), K1(8), K2(8), D(8), Sum(8), Sbox1(8), Sbox2(8) WindowWidth = 640 : WindowHeight = 480 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) texteditor #main.text, 200, 20, 400, 350 button #main.enc, "Encrypt \ Decrypt", [encrypt], ul, 55, 115, 110, 20 button #main.clearKey , "Clear Key", [clearKey], ul, 30, 75, 70, 20 button #main.dec , "Clear Text", [clearText], ul, 110, 75, 70, 20 textbox #main.key, 30, 45, 150, 20 statictext #main.editor, "Type or Paste Text Here", 335, 5, 190, 15 statictext #main.encKey, "Enter Encryption Key (HEX)", 40, 30, 160, 15 Open "untiltled" for dialog as #main #main "trapclose [quit]" wait
'key$ = "9e3779b9a1b2c3d4" 'hex 8 bytes (64 bits) '- original code key value = 16 chars [encrypt] if cript = 1 then [decrypt] redim K1(8) redim K2(8) redim D(8) redim Sum(8) redim Sbox1(8) redim Sbox2(8)
#main.key "!contents? key$" key$ = trim$(key$) data 8, 64, 16, 128, 0, 0, 0, 0 for i = 1 to 8 read alpha Sbox1(i) = alpha ''single bit flip in each byte print Sbox1(i);" "; next i
data 128, 16, 64, 8, 0, 0, 0, 0 for i = 1 to 8 read alpha Sbox2(i) = alpha ''single bit flip in each byte next i
call subKey
#main.text "!contents? text$" text$ = trim$(text$) redim A$(len(text$)) alpha$ = txMain$(text$) alpha$ = trim$(alpha$) #main.text "!cls" cript = 1 #main.text alpha$ print alpha$ restore print "------------------------------------------" wait
[decrypt] #main.text "!contents? text$" text$ = trim$(text$) bravo$ = rxMain$(text$) bravo$ = trim$(bravo$) #main.text "!cls" #main.text bravo$ print bravo$ cript = 0 wait
[clearKey] #main.key "" wait
[clearText] #main.text "!cls" wait
[quit] close #main print "Finished" End
sub subKey num = hexDec(key$) alpha = leftRotate(num,1) hexKey1$ = decHex$(alpha) print hexKey1$, "subKey 1" bravo = leftRotate(num,4) hexKey2$ = decHex$(bravo) print hexKey2$, "subKey2" print "" x = 1 for i = 1 to len(hexKey1$)step 2 chunk$ = mid$(hexKey1$,i,2) byte = hexDec(chunk$) K1(x) = byte print K1(x) x = x + 1 next i print "" x = 1 for i = 1 to len(hexKey2$)step 2 chunk$ = mid$(hexKey2$,i,2) byte = hexDec(chunk$) K2(x) = byte print K2(x) x = x + 1 next i end sub
' rotates bits left n times function leftRotate(num,times) num = num mod two64 r = (num * 2^ times) mod two64 l = int(num /(2^ (64 - times))) leftRotate = r + l end function
function txMain$(text$) x = 1 for i = 1 to len(text$) step 8 chunk$ = mid$(text$,i,8) y = len(chunk$) if y < 8 then chunk$ = chunk$ + addPad$(y) A$(x) = chunk$ '********************* print A$(x), x outStr$ = outStr$ + txRound1$(chunk$) 'envoke the rounds of cipher x = x + 1 'number of text blocks next i txMain$ = outStr$ end function
function addPad$(x) 'pads the final text block if x < 8 then dif = 8 - x for i = 1 to dif pad$ = pad$ + chr$(0) next i end if addPad$ = pad$ end function
function txRound1$(in$) sideL$ = right$(in$,4) 'swap left and right halfs of data block sideR$ = left$(in$,4) perm$ = sideL$ + sideR$ for i = 1 to 4 'process index 1 to 4 of D (new right half of data block) byte = asc(mid$(perm$,i,1)) 'Feistel technique D(i) = byte Sum(i) = K1(i) xor D(i) xor Sbox1(i) 'key xor data then Sbox flips one bit char$ = char$ + chr$(Sum(i)) next i swap$ = char$ + sideR$ 'combine processed half and plain half print swap$ '################ testing Feistel technique txRound1$ = txRound2$(swap$) end function
function txRound2$(in$) sideL$ = right$(in$,4) sideR$ = left$(in$,4) perm$ = sideL$ + sideR$ for i = 1 to 4 byte = asc(mid$(perm$,i,1)) D(i) = byte Sum(i) = K2(i) xor D(i) xor Sbox2(i) char$ = char$ + chr$(Sum(i)) next i swap$ = char$ + sideR$ print swap$ '############ testing txRound2$ = swap$ print "" ' line space end function
print "-----------------------------------------------------------------"
function rxMain$(text$) x = 1 for i = 1 to len(text$) step 8 chunk$ = mid$(text$,i,8) y = len(chunk$) A$(x) = chunk$ '********************* print A$(x), x outStr$ = outStr$ + rxRound1$(chunk$) x = x + 1 'number of text blocks next i rxMain$ = outStr$ end function
function rxRound1$(in$) 'reverse function sequence sideR$ = right$(in$,4) 'unprocessed original left half for i = 1 to 4 byte = asc(mid$(in$,i,1)) D(i) = byte Sum(i) = K2(i) xor D(i) xor Sbox2(i) 'reverse key sequence char$ = char$ + chr$(Sum(i)) next i swap$ = sideR$ + char$ print swap$ '############ testing rxRound1$ = rxRound2$(swap$) 'combine unprocessed original left half end function 'and processed original right half
function rxRound2$(in$) sideR$ = right$(in$,4) for i = 1 to 4 byte = asc(mid$(in$,i,1)) D(i) = byte Sum(i) = K1(i) xor D(i) xor Sbox1(i) 'reverse key sequence char$ = char$ + chr$(Sum(i)) next i swap$ = sideR$ + char$ rxRound2$ = swap$ print "" ' line space end function
|
|
xcoder
Member in Training
Posts: 56
|
Post by xcoder on Feb 2, 2023 4:36:37 GMT
'I tried using the same Sbox (bit flipper) with both rounds of cipher. It appears to disperse the bytes more randomly. print "###############################"
dim A$(100), K1(8), K2(8), D(8), Sum(8), Sbox(8)
print "Sbox"
data 8, 64, 16, 128, 0, 0, 0, 0
for i = 1 to 8
read alpha
Sbox(i) = alpha ''single bit flip in each byte
print Sbox(i);" ";
next i
print:print
global key$, two64
two64 = 2^ 64
key$ = "9e3779b9a1b2c3d4" 'hex 8 bytes (64 bits)
call subKey
print ""
text$ = "the quick brown fox jumps over the lazy dogs back 0123456789"+_
" this is a test of Feistel style block cipher coded in JustBasic 2.0"
alpha$ = txMain$(text$)
print alpha$
print "------------------------------------------"
input "Press Enter to continue: ";entry$
bravo$ = rxMain$(alpha$)
print bravo$
print:print
print "Finished"
End
sub subKey
num = hexDec(key$)
alpha = leftRotate(num,1)
hexKey1$ = decHex$(alpha)
print hexKey1$, "subKey 1"
bravo = leftRotate(num,4)
hexKey2$ = decHex$(bravo)
print hexKey2$, "subKey2"
print ""
x = 1
for i = 1 to len(hexKey1$)step 2
chunk$ = mid$(hexKey1$,i,2)
byte = hexDec(chunk$)
K1(x) = byte
print K1(x)
x = x + 1
next i
print ""
x = 1
for i = 1 to len(hexKey2$)step 2
chunk$ = mid$(hexKey2$,i,2)
byte = hexDec(chunk$)
K2(x) = byte
print K2(x)
x = x + 1
next i
end sub
' rotates bits left n times
function leftRotate(num,times)
num = num mod two64
r = (num * 2^ times) mod two64
l = int(num /(2^ (64 - times)))
leftRotate = r + l
end function
function txMain$(text$)
x = 1
for i = 1 to len(text$) step 8
chunk$ = mid$(text$,i,8)
y = len(chunk$)
if y < 8 then chunk$ = chunk$ + addPad$(y)
A$(x) = chunk$ '*********************
print A$(x), x
outStr$ = outStr$ + txRound1$(chunk$) 'envoke the rounds of cipher
x = x + 1 'number of text blocks
next i
txMain$ = outStr$
end function
function addPad$(x) 'pads the final text block
if x < 8 then
dif = 8 - x
for i = 1 to dif
pad$ = pad$ + chr$(0)
next i
end if
addPad$ = pad$
end function
function txRound1$(in$)
sideL$ = right$(in$,4) 'swap left and right halfs of data block
sideR$ = left$(in$,4)
perm$ = sideL$ + sideR$
for i = 1 to 4 'process index 1 to 4 of D (new right half of data block)
byte = asc(mid$(perm$,i,1)) 'Feistel technique
D(i) = byte
Sum(i) = K1(i) xor D(i) xor Sbox(i) 'key xor data then Sbox flips one bit
char$ = char$ + chr$(Sum(i))
next i
swap$ = char$ + sideR$ 'combine processed half and plain half
txRound1$ = txRound2$(swap$)
end function
function txRound2$(in$)
sideL$ = right$(in$,4)
sideR$ = left$(in$,4)
perm$ = sideL$ + sideR$
for i = 1 to 4
byte = asc(mid$(perm$,i,1))
D(i) = byte
Sum(i) = K2(i) xor D(i) xor Sbox(i)
char$ = char$ + chr$(Sum(i))
next i
swap$ = char$ + sideR$
txRound2$ = swap$
end function
print "-----------------------------------------------------------------"
function rxMain$(text$)
x = 1
for i = 1 to len(text$) step 8
chunk$ = mid$(text$,i,8)
A$(x) = chunk$ '*********************
print A$(x), x
outStr$ = outStr$ + rxRound1$(chunk$)
x = x + 1 'number of text blocks
next i
rxMain$ = outStr$
end function
function rxRound1$(in$) 'reverse function sequence
sideR$ = right$(in$,4) 'unprocessed original left half
for i = 1 to 4
byte = asc(mid$(in$,i,1))
D(i) = byte
Sum(i) = K2(i) xor D(i) xor Sbox(i) 'reverse key sequence
char$ = char$ + chr$(Sum(i))
next i
swap$ = sideR$ + char$
rxRound1$ = rxRound2$(swap$) 'combine unprocessed original left half
end function 'and processed original right half
function rxRound2$(in$)
sideR$ = right$(in$,4)
for i = 1 to 4
byte = asc(mid$(in$,i,1))
D(i) = byte
Sum(i) = K1(i) xor D(i) xor Sbox(i) 'reverse key sequence
char$ = char$ + chr$(Sum(i))
next i
swap$ = sideR$ + char$
rxRound2$ = swap$
end function
|
|
|
Post by xxgeek on Feb 2, 2023 8:08:09 GMT
Excellent xcoder, good job. It fixed it so whatever I paste into the texteditor gets encrypted now, and no jibberish.
I have pasted a few lengthy programs into it and so far they all worked great. I have redone the GUI to work with the new code and added textboxes for the subkeys. Print statements are commented out, some dim statements removed (not needed), text$ now gets re dimmed to it's length so I guess the limit is the JB limit. It seems any key works, any key length works too, doesn't need to be hex either, or does it, is the resulting encrypted text fooling me?
It encrypted an entire 3500 line file in less than 6 seconds on my PC with the print statements turned off.
I would assume that those subkeys should be saved, and the hex key as well, am I correct? Will all 3 be needed if a user needs to decrypt at a later date? Let me know and I'll write code for them go into a list where the user can select any key that was previously used to decrypt past code, or text.
Do me a favor xcoder? I know very little about encryption Could you explain the significance of block encryption. Is it stronger than other encryption methods?
'Text Encryption 'author = xcoder 'Date Feb 2023 'Purpose - To encrypt blocks of text, for example Just Basic Programs ' Just paste your code into the texteditor and press encrypt /decrypt button 'to decrypt, press the same button nomainwin global key$, two64 two64 = 2^64 dim A$(10) 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 \ Decrypt", [encrypt], ul, 55, 115, 110, 20 button #main.clearKey , "Clear Key", [clearKey], ul, 30, 75, 70, 20 button #main.dec , "Clear Text", [clearText], ul, 110, 75, 70, 20 textbox #main.key, 30, 45, 150, 20 textbox #main.subkey1, 30, 220, 150, 20 textbox #main.subkey2, 30, 270, 150, 20 statictext #main.editor, "Type or Paste Text Here", 335, 5, 190, 15 statictext #main.sk1T, "SubKey 1", 85, 205, 60, 15 statictext #main.sk2T, "SubKey 2", 85, 255, 60, 15 statictext #main.encKey, "Enter Encryption Key", 55, 30, 110, 15 Open "Encryptor by xcoder" for dialog as #main #main "trapclose [quit]" wait
'key$ = "9e3779b9a1b2c3d4" 'hex 8 bytes (64 bits) '- original code key value = 16 chars [encrypt] if cript = 1 then [decrypt] #main.key "!contents? key$" data 8, 64, 16, 128, 0, 0, 0, 0 for i = 1 to 8 read alpha Sbox(i) = alpha ''single bit flip in each byte 'Print Sbox(i);" "; next i
call subKey
#main.text "!contents? text$" text$ = trim$(text$) redim A$(len(text$)) alpha$ = txMain$(text$) alpha$ = trim$(alpha$) #main.text "!cls" cript = 1 #main.text alpha$ 'print alpha$ restore 'print "------------------------------------------" wait
[decrypt] bravo$ = rxMain$(alpha$) bravo$ = trim$(bravo$) #main.text "!cls" #main.text bravo$ 'print bravo$ cript = 0 wait
[clearKey] #main.key "" wait
[clearText] #main.text "!cls" wait
[quit] close #main 'print "Finished" End
sub subKey num = hexDec(key$) alpha = leftRotate(num,1) hexKey1$ = decHex$(alpha) #main.subkey1 hexKey1$ 'print hexKey1$, "subKey 1" bravo = leftRotate(num,4) hexKey2$ = decHex$(bravo) #main.subkey2 hexKey2$ 'print hexKey2$, "subKey2" 'print "" x = 1 for i = 1 to len(hexKey1$) step 2 chunk$ = mid$(hexKey1$,i,2) byte = hexDec(chunk$) K1(x) = byte next i 'print "" x = 1 for i = 1 to len(hexKey2$)step 2 chunk$ = mid$(hexKey2$,i,2) byte = hexDec(chunk$) K2(x) = byte 'print K2(x) x = x + 1 next i end sub
' rotates bits left n times function leftRotate(num,times) num = num mod two64 r = (num * 2^ times) mod two64 l = int(num /(2^ (64 - times))) leftRotate = r + l end function
function txMain$(text$) x = 1 for i = 1 to len(text$) step 8 chunk$ = mid$(text$,i,8) y = len(chunk$) if y < 8 then chunk$ = chunk$ + addPad$(y) A$(x) = chunk$ '********************* 'print A$(x), x outStr$ = outStr$ + txRound1$(chunk$) 'envoke the rounds of cipher x = x + 1 'number of text blocks next i txMain$ = outStr$ end function
function addPad$(x) 'pads the final text block if x < 8 then dif = 8 - x for i = 1 to dif pad$ = pad$ + chr$(0) next i end if addPad$ = pad$ end function
function txRound1$(in$) sideL$ = right$(in$,4) 'swap left and right halfs of data block sideR$ = left$(in$,4) perm$ = sideL$ + sideR$ for i = 1 to 4 'process index 1 to 4 of D (new right half of data block) byte = asc(mid$(perm$,i,1)) 'Feistel technique D(i) = byte Sum(i) = K1(i) xor D(i) xor Sbox(i) 'key data then Sbox flips one bit char$ = char$ + chr$(Sum(i)) next i swap$ = char$ + sideR$ 'combine processed half and plain half txRound1$ = txRound2$(swap$) end function
function txRound2$(in$) sideL$ = right$(in$,4) sideR$ = left$(in$,4) perm$ = sideL$ + sideR$ for i = 1 to 4 byte = asc(mid$(perm$,i,1)) D(i) = byte Sum(i) = K2(i) xor D(i) xor Sbox(i) char$ = char$ + chr$(Sum(i)) next i swap$ = char$ + sideR$ txRound2$ = swap$ end function print "-----------------------------------------------------------------"
function rxMain$(text$) x = 1 for i = 1 to len(text$) step 8 chunk$ = mid$(text$,i,8) A$(x) = chunk$ '********************* 'print A$(x), x outStr$ = outStr$ + rxRound1$(chunk$) x = x + 1 'number of text blocks next i rxMain$ = outStr$ end function
function rxRound1$(in$) 'reverse function sequence sideR$ = right$(in$,4) 'unprocessed original left half for i = 1 to 4 byte = asc(mid$(in$,i,1)) D(i) = byte Sum(i) = K2(i) xor D(i) xor Sbox(i) 'reverse key sequence char$ = char$ + chr$(Sum(i)) next i swap$ = sideR$ + char$ rxRound1$ = rxRound2$(swap$) 'combine unprocessed original left half end function 'and processed original right half
function rxRound2$(in$) sideR$ = right$(in$,4) for i = 1 to 4 byte = asc(mid$(in$,i,1)) D(i) = byte Sum(i) = K1(i) xor D(i) xor Sbox(i) 'reverse key sequence char$ = char$ + chr$(Sum(i)) next i swap$ = sideR$ + char$ rxRound2$ = swap$ end function
|
|
xcoder
Member in Training
Posts: 56
|
Post by xcoder on Feb 2, 2023 11:19:17 GMT
A block cipher sends a set group of bytes through the encryption and
decryption process in parallel (4,8,16, bytes). I have known about this
for years, but had no idea how to implement it until I discovered
"Parallel Arrays" one month ago.
Each round of cipher uses it's own key called a sub key.
Sub keys are created at the beginning of the program by
circular bit shifting (rotating) the primary key.
Shorter keys are possible because the unused elements of
a key array will be zeros, which is valid but not strong.
No key at all or using for example,"rustytop" as a key will result in
a scrambled output, but it is not encryption. Notice that "rustytop"
does not include hexidecimal characters. It is therefore the same as zeros.
Thus the scrambled output is the result of swapping the left half and right
half of text data block in the algorithm. Without that swap, there is no
scrambled out. Ooops is that a cipher attack? By the way swapping halfs of a
text block each round and encrypting only one half per round is called a
"Feistal Block cipher."
If the key contains text characters mixed in with hex characters, then only
the hex characters are processed.
For example, suppose the key is "abigtest." the only hex characters are "a,b,e."
And that functions as the key. Not reliable.
A stream cipher is basically a random byte generator algorithm that
is seeded by a key. It generates a stream of cipher bytes that will be
XORed with plain text bytes.
All this information is on the internet.
|
|
|
Post by xxgeek on Feb 3, 2023 1:22:53 GMT
Thanks for the explanation xcoder, it helps to know what's going on. I figured that when no key was use the code was not truly being encrypted, but I didn't know that only the hex bits were being encrypted when a key WAS used.
I'm still not getting the whole picture though.
Lets say I give this app to a friend so we can send secret messages back and forth.
If I encrypt a message and send it, what key(s) will my friend need to use in his app to decypher it. All 3? The main key and both subkeys?, or just 1 or 2 of them? I tried with the main key to no avail, yesterday.
I may have done something wrong though since I haven't quite absorbed what your code is doing yet. In previous versions your code had 2 data statements, one the reverse of the other, now there is only one data statement, so how does the reverse happen? It happens here because everything is still intact, but at another PC they will be starting from scratch.
|
|
xcoder
Member in Training
Posts: 56
|
Post by xcoder on Feb 3, 2023 2:43:46 GMT
In what manner did you send the encrypted message? There is only one external key. Sub keys are generated by the program code.
|
|
|
Post by xxgeek on Feb 3, 2023 7:03:41 GMT
I haven't actually sent the text anywhere. I copied the encrypted text, then shut down the program (the GUI version) I then restart the program and paste the encrypted text, then use the same key used to create that text, but don't get my original text back.
I've tried many ways to rewrite the code and can't get the original text back, unless I leave the program opened and hit the button encrypt / decrypt again.
To be useful as an encryption app I'll need to be able to open the program, paste some encrypted text, type the original key into the box, and decrypt it. So far I have been unable. Still trying though. It may be my own code, not sure.
I'll keep at it until I can understand every line of code and what it does.
|
|
xcoder
Member in Training
Posts: 56
|
Post by xcoder on Feb 3, 2023 7:26:16 GMT
I suspect the GUI text editor isn't up to the task. I am writing a complete text mode command line program using "file dialog" to verify if this code works.
|
|
|
Post by Rod on Feb 3, 2023 7:53:29 GMT
There is the filter bad character preferences check box to look at, test without it checked and with it checked.
|
|
|
Post by xxgeek on Feb 3, 2023 9:48:40 GMT
There is the filter bad character preferences check box to look at, test without it checked and with it checked. Good idea, but on or off makes no difference in the resulting text . I don't believe it is the text editor itself either since it handles it ok if I don't close the program I can encrypt and decrypt it all day long without a problem. It may have something to do with the clipboard and the way it handles the encrypted text of ASCII characters. When I paste my text(which is the code of this app) into the editor and encrypt it, there are 'multiple' lines in the resulting encrypted text. When I copy the encrypted text, close the program, reopen the program and then paste it back into the texteditor, there is 'ONE' long line of text. What this means, and what to do about it, I am at a loss.
|
|
|
Post by Rod on Feb 3, 2023 15:06:06 GMT
When you display text only a proportion of the characters are displayable. Those less than asc(32) are control characters which any respectable text editor will not display but will obey. Those above asc(127) are extended characters, stranger glyphs, which few text editors will display. So if you want to use a text editor to view copy or paste your cypher you need to work with a cypher that uses a subset of characters between 32 and 127.
In a cypher many characters are displaced or swapped and usually the cypher uses all characters available. So the formatting characters CR LF which text editors use to break and display neat lines of text will get corrupted or swapped out.
The cypher needs to be in a file. You need to read it in binary format, or as a complete string into a string variable. Then work it character by character to be sure a text editor does not mess with the encryption or misinterpret the encryption. The unencrypted text will be displayable characters, or at least should be. But that's not to say the the encryption will swap some of them to undisplayable characters during the encryption.
|
|
|
Post by xxgeek on Feb 3, 2023 21:33:37 GMT
Rod that makes sense. I did consider that but dismissed it because 1. There are control characters in the text pasted into the editor. 2. If I don't copy the encrypted text, and past it back into the editor after closing/reopening the app everything works fine. How can it work fine if there were control characters introduced in the cyphering? (This part seems illogical) Anyway, all 10000 experiments I have tried point to 'something' goes wrong, and it has 'something' to do with ASCII characters. Rod your knowledge and experience has always led me in the right direction so I am inclined to believe you are spot on as usual. Somehow, just viewing the initial encrypted text in the editor is ok, but to copy/paste encrypted text isn't. (Still doesn't make sense to me, but I'm sure it will by the time we get this working) So, here goes another 10000 experiments
|
|
|
Post by Rod on Feb 4, 2023 8:17:46 GMT
You need to print a list of the asc characters before and after to see what is changed by the copy paste. I would save to a file and then compare the files character by character till they differ.
|
|
|
Post by xxgeek on Feb 4, 2023 9:22:04 GMT
Popping in to let you know it was not the ASCII thing, it was not the texeditor, and it was not xcoders code. xcoders code wasn't designed for what I was doing with it, and I had to understand all his code before I could get it right.
It was my own logic causing the issues. I had not preserved, or rather had not re-created some of the variables needed to decrypt.
It works great now. I have it write the encrypted text to a file using Rods suggestion (binary type) as well as to the editor. When decrypting, it reads the file(if it exists) and puts the decrypted text in the editor.
If the file doesn't exist, it reads the editor for users pasted text.
I can now copy the encrypted text, paste it, then decrypt it, so it will work as an encryption app for just about any text, and it's pretty fast too.
I'll post the code when I clean it up, once I get some sleep.
|
|