Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
105.. bit encryption.
#1
Code:
DECLARE SUB decrypt (array1() AS INTEGER, key1() AS INTEGER)
DECLARE SUB encrypt (array1() AS INTEGER, key1() AS INTEGER)
CLS

RANDOMIZE TIMER

string1$ = "Don't you just love 'Married with Children'?"
len1% = LEN(string1$)
DIM array1(len1% - 1) AS INTEGER

FOR i% = 0 TO UBOUND(array1)
array1(i%) = ASC(MID$(string1$, i% + 1, 1))
PRINT array1(i%);
NEXT i%

'MUST BE ODD! (or, even, if you count the zeroth element)
'MUST NOT EXCEED: max.bits.data.can.hold - bits.required(max.plaintext.number)


'In this case, a max of 255 must not exceed a key length of 7
'Each time the bits required can possibly double by almost 2.
'Program will not automatically error if length of 7 is exceeded,
'but can error with the right key combination.

'For signed integers, each sub key is made up of 15 bits (MOD max length of string). Theoretically, then, each key holds 7 subkeys * 15 bits.
'That's 105 bits, folks. Assuming there aren't any repeat keys, that's
'2^105, or 40,564,819,207,303,340,847,894,502,572,032, combinations.

keyLength% = 7
DIM testkey(keyLength% - 1) AS INTEGER

'DO
FOR i% = 0 TO keyLength% - 1
testkey(i%) = INT(RND * len1%)
NEXT i%

encrypt array1(), testkey()

PRINT : PRINT : FOR i% = 0 TO UBOUND(array1): PRINT array1(i%); : NEXT i%

decrypt array1(), testkey()

'IF INKEY$ <> "" THEN EXIT DO
'LOOP
PRINT : PRINT : FOR i% = 0 TO UBOUND(array1): PRINT array1(i%); : NEXT i%

SUB decrypt (array1() AS INTEGER, key1() AS INTEGER)

keyLength% = UBOUND(key1)
arrayLength% = UBOUND(array1) + 1
n% = keyLength%

DO
i% = key1%(n%) MOD arrayLength%
k% = (i% + arrayLength% - 1) MOD arrayLength%
temp1% = array1(i%)
DO
i% = i% + 1
IF i% = arrayLength% THEN i% = 0
IF i% = k% THEN EXIT DO
j% = i% - 1: IF j% < 0 THEN j% = j% + arrayLength%
array1(i%) = array1(i%) + array1(j%)
LOOP
n% = n% - 1
IF n% = -1 THEN EXIT DO


i% = key1%(n%) MOD arrayLength%
temp1% = array1(i%)
k% = (i% + arrayLength% - 1) MOD arrayLength%
DO
i% = i% + 1
IF i% = arrayLength% THEN i% = 0
IF i% = k% THEN EXIT DO
temp2% = array1(i%)
array1(i%) = array1(i%) - temp1%
temp1% = temp2%
LOOP
n% = n% - 1
LOOP
END SUB

SUB encrypt (array1() AS INTEGER, key1() AS INTEGER)

keyLength% = UBOUND(key1)
arrayLength% = UBOUND(array1) + 1

DO
i% = key1%(n%) MOD arrayLength%
temp1% = array1(i%)
k% = (i% + arrayLength% - 1) MOD arrayLength%
DO
i% = i% + 1
IF i% = arrayLength% THEN i% = 0
IF i% = k% THEN EXIT DO
temp2% = array1(i%)
array1(i%) = array1(i%) - temp1%
temp1% = temp2%
LOOP
n% = n% + 1
IF n% > keyLength% THEN EXIT DO


i% = key1%(n%) MOD arrayLength%
k% = (i% + arrayLength% - 1) MOD arrayLength%
temp1% = array1(i%)
DO
i% = i% + 1
IF i% = arrayLength% THEN i% = 0
IF i% = k% THEN EXIT DO
j% = i% - 1: IF j% < 0 THEN j% = j% + arrayLength%
array1(i%) = array1(i%) + array1(j%)
LOOP
n% = n% + 1
LOOP
END SUB

The only drawback so far is that encryption can double size of the text for every +2 in the key length. (to be extra safe you can say quadruple. Haven't analyzed it thoroughly. But with 99% certainty I can say that the maximum is double)

This is why you can only have 7 15-bit keys....
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Messages In This Thread
105.. bit encryption. - by Agamemnus - 01-14-2004, 09:00 AM
105.. bit encryption. - by Agamemnus - 01-14-2004, 09:27 AM
105.. bit encryption. - by KiZ - 01-14-2004, 03:11 PM
105.. bit encryption. - by Agamemnus - 01-14-2004, 09:38 PM
105.. bit encryption. - by KiZ - 01-14-2004, 11:14 PM
105.. bit encryption. - by Zack - 01-14-2004, 11:24 PM
105.. bit encryption. - by Agamemnus - 01-15-2004, 05:20 AM
105.. bit encryption. - by Zack - 01-15-2004, 07:21 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)