Qbasicnews.com
Let's have an encryption CHALLENGE! - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QbasicNews.Com (http://qbasicnews.com/newforum/forum-3.html)
+--- Forum: Challenges (http://qbasicnews.com/newforum/forum-10.html)
+--- Thread: Let's have an encryption CHALLENGE! (/thread-1160.html)

Pages: 1 2 3 4 5 6 7 8 9


Let's have an encryption CHALLENGE! - Agamemnus - 06-11-2003

or not. you know, these things are never breakable until they are actually commercially used? :evil:

anyways, some thoughts i had:
http://www.neozones.com/Board/Messages/41082.shtml

Requirements!
1) A KEY...
2) No one can make a program in the forseeable future to break it...
3) Must be able to encrypt any-length (within....oh.... 64K?) byte-file!

BONUS:
1) Unbreakable (need the key, or guessed the key)
2) Long key (key length must proportional to difficult of breaking the encryption..)
3) You post the proof that it is unbreakable!
4) The IEEE makes your encryption program its #1 choice!

WINNER will be decided by:
1) speed of encryption (must not be exponentially slow)
2) unbreakability
3) Code is original and in BASIC!! Smile
4) ME! :rotfl:


Let's have an encryption CHALLENGE! - whitetiger0990 - 06-11-2003

Code:
INPUT word$
PRINT x
Nobody can break it.
J/k
Is this good.

Code:
CLS

RANDOMIZE TIMER
ky = INT(RND * 1000)

DIM alpha$(27)
alpha$(1) = " "
al = 65
FOR a = 2 TO 27
alpha$(a) = CHR$(al)
al = al + 1
NEXT a

redo:
INPUT "d/e ", e$
SELECT CASE LEFT$(LCASE$(e$), 1)
CASE "d"
  GOTO decrypt
CASE "e"
  GOTO encrypt
CASE ELSE
  GOTO redo
END SELECT

encrypt:
INPUT word$
word$ = UCASE$(word$)
FOR i = 1 TO LEN(word$)
temp$ = MID$(word$, i, 1)
FOR a = 1 TO 27
  tmp = a
  IF temp$ = alpha$(a) THEN EXIT FOR
NEXT a
PRINT tmp * 2 * ky * i;
PRINT " ";
NEXT i
PRINT
PRINT "Key = "; ky
END

decrypt:
INPUT "Key ", ky$
ky = VAL(LTRIM$(ky$))
PRINT "Enter numbers 1 at a time. Enter q to print word"; ""
i = 1
DO
redon:
PRINT i; ", Enter number ";
INPUT "", n$
IF LCASE$(LEFT$(n$, 1)) = "q" THEN
PRINT word$
EXIT DO
ELSEIF VAL(n$) = 0 THEN
i = i + 1: GOTO redon
END IF
n = VAL(n$)
'IF n MOD 2 = 0 THEN
tmp = INT(n / i / ky / 2)
IF tmp > 27 THEN PRINT "Error": GOTO redon
word$ = word$ + alpha$(tmp)
i = i + 1
LOOP
END



Let's have an encryption CHALLENGE! - Agamemnus - 06-11-2003

It's fine, but easily breakable, for two reasons:

1) After dividing by the current position of the number, I can analyze the number frequency and match it up with letter frequency. (each letter in the English alphabet has a certain frequency of occurence to it)

For very small words or phrases your program will undoubtedly work: a key size that is perhaps 1/4th that of the message size might not always be breakable in any way.. a key size that is equal to the message size is UNbreakable. (obviously Smile)

2) Go through every combination and find one combo with English words. [although I'd just go with (1)]

Regular e-commerce encryption is 32 or 64 or 128 (I think they have 128) bit. 1000 is only 10 bit Sad. Doesn't matter if you changed it to a long, easily breakable.

But Good Effort.

Will post decryption program (w/out key) soon...


Let's have an encryption CHALLENGE! - relsoft - 06-11-2003

um... Mango??? You there???? ;*)


here it is - Agamemnus - 06-11-2003

took some work *whew*

Code:
'WE "(Whitetiger Encryption)" decrypter:
'http://www.geocities.com/pisforpi/flyingsoft

CLS
RANDOMIZE TIMER
option1% = 1

cipherkey& = 1 + INT(RND * 1000)

IF option1% = 1 THEN
word$ = "Agamemnus >> Hello, whitetiger's smiley. How does it feel to be the smartest avatar in the world?"
word$ = word$ + "whitetiger's smiley >> Pretty good, actually. How does it feel to be talking to a smiley, Agamemnus?"
word$ = word$ + "Agamemnus >> Pretty good, actually."
word$ = word$ + "Agamemnus >> *clears voice*: 'The quick brown fox jumped over the lazy dog(s)', I think."

ELSE

'Nonsense below.

word$ = word$ + "That can I;"
word$ = word$ + "At least, the whisper goes so. Our last king,"
word$ = word$ + "Whose image even but now appear'd to us,"
word$ = word$ + "Was, as you know, by Fortinbras of Norway,"
word$ = word$ + "Thereto prick'd on by a most emulate pride,"
word$ = word$ + "Dared to the combat; in which our valiant Hamlet--"
word$ = word$ + "For so this side of our known world esteem'd him--"
word$ = word$ + "Did slay this Fortinbras; who by a seal'd compact,"
word$ = word$ + "Well ratified by law and heraldry,"
word$ = word$ + "Did forfeit, with his life, all those his lands"
word$ = word$ + "Which he stood seized of, to the conqueror:"
word$ = word$ + "Against the which, a moiety competent"
word$ = word$ + "Was gaged by our king; which had return'd"
word$ = word$ + "To the inheritance of Fortinbras,"
word$ = word$ + "Had he been vanquisher; as, by the same covenant,"
word$ = word$ + "And carriage of the article design'd,"
word$ = word$ + "His fell to Hamlet. Now, sir, young Fortinbras,"
word$ = word$ + "Of unimproved mettle hot and full,"
word$ = word$ + "Hath in the skirts of Norway here and there"
word$ = word$ + "Shark'd up a list of lawless resolutes,"
word$ = word$ + "For food and diet, to some enterprise"
word$ = word$ + "That hath a stomach in't; which is no other--"
word$ = word$ + "As it doth well appear unto our state--"
word$ = word$ + "But to recover of us, by strong hand"
word$ = word$ + "And terms compulsatory, those foresaid lands"
word$ = word$ + "So by his father lost: and this, I take it,"
word$ = word$ + "Is the main motive of our preparations,"
word$ = word$ + "The source of this our watch and the chief head"
word$ = word$ + "Of this post-haste and romage in the land."
END IF

word$ = UCASE$(word$)
FOR i% = 1 TO LEN(word$)
temp% = ASC(MID$(word$, i%, 1))
IF temp% < 65 THEN GOTO contfor1
IF temp% > 90 THEN GOTO contfor1
word.temp$ = word.temp$ + CHR$(temp%)
contfor1:
NEXT i%

word$ = word.temp$
len.ciphertext% = LEN(word$)
DIM SHARED ciphertext&(1 TO len.ciphertext%)
FOR i& = 1 TO len.ciphertext%
temp& = ASC(MID$(word$, i&, 1))
ciphertext&(i&) = cipherkey& * i& * 2& * temp&
NEXT i&

PRINT "Secret key:"; cipherkey&
cipherkey& = 0
DIM SHARED probability(1 TO 26) AS INTEGER
probability(1) = 820
probability(2) = 150
probability(3) = 280
probability(4) = 430
probability(5) = 1270
probability(6) = 220
probability(7) = 200
probability(8) = 610
probability(9) = 700
probability(10) = 20
probability(11) = 80
probability(12) = 400
probability(13) = 240
probability(14) = 680
probability(15) = 750
probability(16) = 190
probability(17) = 10
probability(18) = 600
probability(19) = 630
probability(20) = 910
probability(21) = 280
probability(22) = 100
probability(23) = 230
probability(24) = 10
probability(25) = 200
probability(26) = 10

DIM SHARED letter.num&(1 TO 26)
DIM SHARED letter.freq#(1 TO 26)
DIM SHARED letter.is&(1 TO 26)

DIM SHARED plaintext%(1 TO len.ciphertext%)
DIM SHARED plaintext.string$

'get probabilities of each number that appeared.
j% = 0
FOR i% = 1 TO len.ciphertext%
cur.num& = ciphertext&(i%) / (i% * 2)

FOR i2% = 1 TO j%
IF cur.num& = letter.num&(i2%) THEN
letter.freq#(i2%) = letter.freq#(i2%) + 1
GOTO contfor2
END IF
NEXT i2%

j% = j% + 1
letter.num&(j%) = cur.num&
letter.freq#(j%) = 1
contfor2:
NEXT i%

'scale the probabilities..
FOR i% = 1 TO j%
tot.freq% = tot.freq% + letter.freq#(i%)
NEXT i%
FOR i% = 1 TO j%
letter.freq#(i%) = 10000 * letter.freq#(i%) / tot.freq%
NEXT i%

'match up the probabilities.
FOR k% = 26 TO 1 STEP -1'26
min.least.diff% = 20000
FOR i% = 1 TO 26
least.diff% = ABS(letter.freq#(i%) - probability(k%))
IF least.diff% <= min.least.diff% THEN
min.least.diff% = least.diff%
most.likely.num& = letter.num&(i%)
END IF
NEXT i%
letter.is&(k%) = most.likely.num&
NEXT k%

'get the key!
FOR k% = 1 TO 26
FOR i% = 1 TO len.ciphertext%
IF letter.is&(k%) = ciphertext&(i%) / (i% * 2) THEN
temp# = ciphertext&(i%) / i%
temp# = temp# / k%
temp# = temp# / 26
temp# = temp# / len.ciphertext%
avg.num# = avg.num# + temp#
END IF
NEXT i%
NEXT k%

cipherkey& = avg.num#
redo1:

'match up the letters..
FOR i% = 1 TO len.ciphertext%
temp# = ciphertext&(i%) / 2
temp# = temp# / i%
temp# = temp# / cipherkey&

'without these corrections, it would be inaccurate..
IF temp# > 90 THEN cipherkey& = cipherkey& + 1: GOTO redo1
IF temp# < 65 THEN cipherkey& = cipherkey& - 1: GOTO redo1
plaintext%(i%) = temp#
NEXT i%

PRINT "Program found this key:"; cipherkey&
PRINT

'convert array to string
FOR i% = 1 TO len.ciphertext%
plaintext.string$ = plaintext.string$ + CHR$(plaintext%(i%))
NEXT i%

PRINT plaintext.string$



Let's have an encryption CHALLENGE! - oracle - 06-11-2003

Try this on for size. Remember you won't have access to the key, but you can access the file with the encrypted string in it.
Code:
'                       **  Encryption routine **

'                             By the oracle

' This is a function I made up a while ago when working with zack on a
' GUI login for QBasic. We never got around to finishing it...

' This program has a key, it is outputted to a file at the moment, but
' this could be changed in the future.

DECLARE SUB encrypt (encrypt$)

RANDOMIZE TIMER
CLS
PRINT "The oracle's encryption routine"
PRINT "This program will take a string that you input and encrypt it."
PRINT "The result is outputted to a file"
PRINT "F-keys etc will be trimmed from the string. Only valid characters, please!"
PRINT
INPUT "What is the string you want to encrypt? ", enc$

t# = TIMER
encrypt enc$
t# = TIMER - t#

PRINT "The string has been outputted to strng.txt."
PRINT "The encryption took "; t#; "seconds."
INPUT "Do you want to view the string? ", yn$
IF LCASE$(LEFT$(yn$, 1)) = "y" THEN
  OPEN "strng.txt" FOR INPUT AS #1
  INPUT #1, a$
  PRINT a$
  WHILE INKEY$ = "": WEND
  CLOSE #1
END IF
END

SUB encrypt (enc$)

' DIM stuff

DIM rndlen AS INTEGER, ikey AS INTEGER, i AS INTEGER, handle AS INTEGER, keyhandle AS INTEGER

' Make a random key

rndlen = INT(RND * 500)
FOR i = 1 TO rndlen
  key$ = key$ + CHR$(INT(RND * 95) + 32)
NEXT i

' Encrypt the inputted string based on the key.

key$ = "!"
FOR i = 1 TO LEN(enc$)
  handle = ASC(MID$(enc$, i, 1))  ' I'm unfamiliar with PEEK
  ikey = ikey + 1
  IF ikey > LEN(key$) THEN ikey = 1
  keyhandle = ASC(MID$(key$, ikey, 1))
  temp& = INT(handle * keyhandle + 9999)
  temp$ = LTRIM$(STR$(temp&))
  FOR inc = LEN(temp$) TO 7
    temp$ = "0" + temp$
  NEXT inc
  encryptedstring$ = encryptedstring$ + temp$
NEXT i


OPEN "strng.txt" FOR OUTPUT AS #1
PRINT #1, encryptedstring$
CLOSE
OPEN "key.txt" FOR OUTPUT AS #1
PRINT #1, key$
CLOSE

END SUB

Beat that!


Let's have an encryption CHALLENGE! - Neo - 06-11-2003

I just finished this Encryption routine for the KetOn library yesterday:

For ciphering:
Code:
FUNCTION KT.ENC.DifCipher$(ToCipher AS STRING, Frequency AS INTEGER)
    'a completely new ciphering method -> Dif Ciphering
    'by Neo Deus Ex Machina

    'I thought of this ciphering, it's completely new ;) lol
    'It uses the difference with a sequent character from the base character
    freqnow = Frequency
    basechar$ = ""
    ans$ = ""
    FOR i = 1 TO LEN(ToCipher)
                IF freqnow = Frequency THEN
                    freqnow = 1
                    basechar$ = MID$(ToCipher, i, 1)
                    ans$ = ans$ + basechar$
                ELSE
                    freqnow = freqnow + 1
                    NewChar$ = MID$(ToCipher, i, 1)
                        dif% = ASC(NewChar$) - ASC(basechar$)
                        IF dif% >= 0 THEN
                            ans$ = ans$ + CHR$(dif%)
                        ELSE
                                ans$ = ans$ + CHR$(256 + dif%)
                        END IF
                END IF
    NEXT i
    KT.ENC.DifCipher$ = ans$
END FUNCTION


This is how you can cipher a text file:
Code:
OPEN "MYTEXT.TXT" FOR INPUT AS #1
   WHILE NOT EOF(1)
      LINE INPUT #1, dat$
      IF dat$ <> "" THEN PRINT KT.ENC.DifCipher$(dat$, LEN(dat$))
   WEND
CLOSE #1

Then try to decipher the code by hand! Smile lol


BASIC encryption - Mango - 06-11-2003

Quote:um... Mango??? You there???? ;*)

So...here's a compiled program I wrote in QB that encrypts/unencrypts.

http://www.tcdn.teiher.gr/upload/download.asp?fileid=682

I'm posting the compiled version and not the source because it is so much easier to use. Just unzip then drop the file to be encrypted onto the EXE file...you will be prompted for a password and the encrypted file "filein.jkc" will be placed in the same directory with the original file. To unencrypt, just drop the encrypted file on the EXE and same deal...the unencrypted file will be "filein.ckj". You will have to change the extension back to its original value.

I've been learning about encryption on sci.crypt newsgroup. There's basically no easy way to break my scheme...however, I've learned of several potential weaknesses. I'm in the process of addressing these. I've actually written the code to address all the issues...but I haven't put it all together because the new version will, by necessity, produce an encrypted file that's slightly longer than the original...this means I need to come up with a uniform file-structure and file reader...If I'm going to make the effort, I want the program to be attractive enough that someone might actually use it. I bought a book on c++ yesterday, and plan to port my code as a way to learn c.

Anyway, the version I posted here works well and is very easy to use if you use the drag-n-drop method. If you simply launch the exe instead, you will find the file navigation very awkward (although it does work, once you understand it).

The main weaknesses in my scheme is the following:

if an attacker knows the contents of an encrypted file, he can steal the key...this is a major proplem...I addressed it by making the key dependent on both a checksum value and the password...this means that even if an attacker knows the contents of an encrypted file, the key he can recover will only unencrypt a file that happens to have the same 32-bit checksum and was encrypted with the same password...not likely to be of value to an attacker, since he *already* had the file he's attacking.


In addressing this issue, it is required to attach an encrypted version of the checksum to the original encrypted file. Then, to unencrypt the file, the user first unencrypts the checksum value (with a key derived from the encryptd file checksum and the password). This key is used to recover the original checksum which is then used (along with the password) to generate the file encryption key...and the file is unencrypted.

There are several subtilties to this...such as...with the newer scheme, the encrypted file is by necessity longer by the checksum...which means that the symmetry of encrypting and decrypting is lost...which means a file reader is needed to unencrypt. This has some advantages...such as the log file is no longer needed...rather it's easy to have the program output the original filename. It also gives the opportunity to carry additional info with the file such as a "request confirmation" flag, or a "USE XXXXXXXXX as password in reply" flag (encrypted, of course). All of this is going into V4.0...

Also...v4 uses shift registers so that I can generate the key 32-bits in parrallel, instead of 1-bit at a time. This has given me an approx 25x speed increase for key generation, which allows me to use much larger keys...anyway...even though I have my checksum code finalized, my key-update code secured, and the parallel key generation code working, I don't plan to create the unencrypter in BASIC.

The code that I compiled into this exe is 16 kb (with comments) and has 16 subs.

Cheers...


Let's have an encryption CHALLENGE! - Agamemnus - 06-11-2003

From now on, can we just stick to:
key%, ciphertext% (output), and plaintext% (input) for ease of use? Smile

oracle:
First, I'd get analyze the ciphertext string and find the average repetition length of numbers after zero. (which will be 100% len.temp$ - 7).

Then I'd remove the extras.

Then, I'd divide the string into numbers according to average.repetition.length% + 7 (or somethin like that).

Then I'd subtract 9999 from each number. Then, I'd do the same thing as I did before.

*OR*
I can even just factor a bunch of numbers and get the factor that appears in all of them. If I reach a number that has two factors and one of those factors didn't appear before, the other one must be the key.

Then I divide by the key.

*OR*
I go through every number from 1 to 256 and divide each number by that. As soon as I get a number that doesn't divide evenly (gets a remainder), I skip that test key and go on to the next. The one that passes is the one that I will use to divide each number in the number array and get the answer.

--------------------------------------------

Neo:

I changed the variables in your code:

Code:
FUNCTION KT.ENC.DifCipher$(plaintext$ AS STRING, key AS INTEGER)

'a completely new ciphering method -> Dif Ciphering
'by Neo Deus Ex Machina

'I thought of this ciphering, it's completely new ;) lol
'It uses the difference with a sequent character from the base character

base.char$ = MID$(plaintext$, 1, 1)
ans$ = base.char$
cur.key% = 1

FOR i = 2 TO LEN(plaintext$)

IF cur.key% = key THEN
cur.key% = cur.key% + 1
base.char$ = mid$(plaintext$, i, 1)
ans$ = ans$ + base.char$
ELSE
new.char$ = MID$(plaintext$, i, 1)
diff% = ASC(new.char$) - ASC(base.char$)
IF diff% >= 0 THEN ans$ = ans$ + CHR$(diff%) ELSE ans$ = ans$ + CHR$(256 + diff%)
END IF

NEXT i

KT.ENC.DifCipher$ = ans$
END FUNCTION

I'm sure it's breakable but I can't figure out how, yet.


Let's have an encryption CHALLENGE! - Agamemnus - 06-11-2003

Mango: I have been thinking of using CA (2D, though) to encrypt files. Using a key to generate another, larger key and then adding it into the plaintext is possibly unbeatable.

What do you mean by "The key is updated as it is used"??????????