Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm looking for a reliable encryption routine both for...
#11
I wrote this a while back for the encryption challenge. Nobody ever said whether it was good or not, but I thought it was kinda neat, so here if ya wanna take a look at it =)

It doesn't use a key. It's an ascii-value shifter, but it doesn't shift by letter (therefore, E will not always become A, for example). Instead it uses both the ascii value of the (already encrypted) character before it, and that of the character after it to determine how much the shift is. Furthermore, it uses the location of the letter within the string to further alter the ASC value.

I feel like this would be very difficult to decrypt without knowing the formula.

*peace*

Meg.

Code:
tt = 1000
'*** ^^ CHANGE THIS VALUE TO AFFECT SPEED ^^ ***

CLS
LINE INPUT "Enter string to encrypt: ", i$

'******************* ENCRYPT ********************
LOCATE 3, 1: PRINT i$
FOR x% = 1 TO LEN(i$)
     IF x% > 1 THEN pre$ = MID$(i$, x% - 1, 1) ELSE pre$ = " "
     IF x% < LEN(i$) THEN aft$ = MID$(i$, x% + 1, 1) ELSE aft$ = " "
      
     k% = (ASC(pre$) + ASC(aft$)) \ 2
     k% = k% XOR x%
    
     n% = ASC(MID$(i$, x%, 1))
     n% = n% + k%
     DO
          IF n% > 126 THEN n% = n% - 95
     LOOP UNTIL n% < 127

     i$ = LEFT$(i$, x% - 1) + CHR$(n%) + RIGHT$(i$, LEN(i$) - x%)
     FOR t = 1 TO tt
          LOCATE 3, x%: PRINT CHR$(INT(RND * 95) + 32)
     NEXT t
     LOCATE 3, 1: PRINT i$; k%
NEXT x%

LOCATE 5, 1: PRINT "Encrypted string: "; i$

'****************** UNENCRYPT *******************
LOCATE 7, 1: PRINT i$
FOR x% = LEN(i$) TO 1 STEP -1
     IF x% > 1 THEN pre$ = MID$(i$, x% - 1, 1) ELSE pre$ = " "
     IF x% < LEN(i$) THEN aft$ = MID$(i$, x% + 1, 1) ELSE aft$ = " "

     k% = (ASC(pre$) + ASC(aft$)) \ 2
     k% = k% XOR x%
    
     n% = ASC(MID$(i$, x%, 1))
     n% = n% - k%
     DO
          IF n% < 32 THEN n% = n% + 95
     LOOP UNTIL n% > 31

     i$ = LEFT$(i$, x% - 1) + CHR$(n%) + RIGHT$(i$, LEN(i$) - x%)
     FOR t = 1 TO tt
          LOCATE 7, x%: PRINT CHR$(INT(RND * 95) + 32)
     NEXT t
     LOCATE 7, 1: PRINT i$; k%
NEXT x%

LOCATE 9, 1: PRINT "Unencrypted string: "; i$
Reply
#12
Well, thanx for the trouble people but I used Neo's encrpytion and it rocks! It is now my new standard. And you know how much I love standards.

Confusedhifty:
Reply
#13
Yeah, thinking it over I realized that non-bit-encryption is way better than using stuff like XOR and AND and OR all the time. Because bit encryption could be cracked (like Neo cracked mine) just by flipping open a hex editor and staring at the values there.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#14
a lil late prolly but owell, i was bored.

Code:
DEFINT A-Z

DECLARE FUNCTION Encode$ (St$)
DECLARE FUNCTION Decode$ (St$)

CLS
EncStr$ = Encode$("Hello, World!")
PRINT EncStr$

DecStr$ = Decode$(EncStr$)
PRINT DecStr$



Defint A-z
FUNCTION Decode$ (St$)

Code = 128
FOR I = 1 TO LEN(St$)
     Char = ASC(MID$(St$, I, 1)) XOR Code

     Bit = 1
     FOR J = 1 TO 8
          Bit = Bit * 2
          IF Char AND (Bit - 1) THEN Code = (Code + (((Char MOD 3) - 1) * Bit)) \ 4
     NEXT

     IF Code > 255 THEN Code = Code - 256
     IF Code < 0 THEN Code = Code + 256

     Enc$ = Enc$ + CHR$(Char)
NEXT

Decode$ = Enc$


END FUNCTION

Defint A-z
FUNCTION Encode$ (St$)

Code = 128
FOR I = 1 TO LEN(St$)
     Char = ASC(MID$(St$, I, 1))
     Enc$ = Enc$ + CHR$(Char XOR Code)

     Bit = 1
     FOR J = 1 TO 8
          Bit = Bit * 2
          IF Char AND (Bit - 1) THEN Code = (Code + (((Char MOD 3) - 1) * Bit)) \ 4
     NEXT

     IF Code > 255 THEN Code = Code - 256
     IF Code < 0 THEN Code = Code + 256
NEXT

Encode$ = Enc$

END FUNCTION
very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Reply
#15
Quote:Well, thanx for the trouble people but I used Neo's encrpytion and it rocks! It is now my new standard. And you know how much I love standards.

Confusedhifty:
Thanks! Hope it helps you! Wink Btw, all encryption routines Zack and I wrote will be in NeoLib v1.6 as well! Big Grin

Quote:Yeah, thinking it over I realized that non-bit-encryption is way better than using stuff like XOR and AND and OR all the time. Because bit encryption could be cracked (like Neo cracked mine) just by flipping open a hex editor and staring at the values there.
Hehe Big Grin Your latest decryptionchallenge (via mail) was difficult btw. I took 50 minutes to decrypt it! Wink And indeed... letter encryption or something like shifting or so is much harder to decrypt than bit encryptions! Tongue
Reply
#16
This new routine was obviously inspired by Neo's.
it works the same way as neo's but it only needs 1 routine to encrypt or decrypt, just run the encrypted string/number back thru it to decrypt.


Code:
SUB bsCode (Segment, Offset, Length&, Pass$)

DEF SEG = Segment

Code = 128
IF Length& > 32767 THEN
       FOR I& = 0 TO Length& - 1
            Sp& = Offset + I&
            J = J + 1
            IF J = LEN(Pass$) THEN J = 1
            PassByte = ASC(MID$(Pass$, J, 1))
            Char = PEEK(Sp&) XOR PassByte
            POKE Sp&, Char XOR (Code AND 255)
            Code = Code + (((Length& Xor Code) AND 15) - 8) * (I& AND 15)
       NEXT
    ELSE
       FOR I = 0 TO Length& - 1
            Sp& = Offset + I
            J = J + 1
            IF J = LEN(Pass$) THEN J = 1
            PassByte = ASC(MID$(Pass$, J, 1))
            Char = PEEK(Sp&) XOR PassByte
            POKE Sp&, Char XOR (Code AND 255)
            Code = Code + (((Length& Xor Code) AND 15) - 8) * (I AND 15)
       NEXT
END IF

DEF SEG

END SUB
very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)