#Repeating pattern in encryption

80 messages · Page 1 of 1 (latest)

smoky pulsar
#

Hey! I need some help with my first encryption algorithm.
I'm getting a repeating pattern after a while and i don't get why. Can anyone help me?

pearl chasmBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

smoky pulsar
#
    {
        int u = SL/2 + i;
        char L = S[i];
        char R = S[u];

        for (short int k = 0; k < 4; k++)
        {
            short int T = A[k][k + 1] + i;

            L ^= T + K;
            R ^= T + C(K);
        }
        L ^= C(K);
        R ^= A[0][1] * K;

        if (L == 0 || L == 10 || L == 32 || L == 8 || L == 7 || L == 9 || L == 13) L <<= 1;
        if (R == 0 || R == 10 || R == 32 || R == 8 || R == 7 || R == 9 || R == 13) R <<= 1;

        S[i] = L;
        S[u] = R;
    }```
#

this is for both encryption and decryption

#
{
    int B = A[0][X >> 32 & 8] + A[3][X >> 16 & 4];
    return (B ^ A[1][X >> 8 & 2]) >> 12;
}```
little nymph
#

the real answer is to never roll your own encryption

smoky pulsar
#

:(

little nymph
#

I don't know what S and A are

smoky pulsar
#

S is the string

#
        {07321,13908,86778,44329,53288,81847,82277,56246},
        {31701,87817,72960,23541,30606,72136,04600,79250},
        {87402,56425,34708,79089,13729,17228,28611,51591},
        {69054,65937,46161,93238,40363,89313,13643,27137}
};```
little nymph
#

and you only read it down the minor diagonal, or the first two rows?

#

why

weary finch
#

i wouldn't discourage it if it's just for fun, but if you're actually trying to encrypt something real, you should use an existing encryption algorithm because most likely yours will be cracked easily

little nymph
#

I don't even think this is possible to decrypt

#

there are bitshifts

smoky pulsar
#

the encryption algorithm works for decypriotn as well

smoky pulsar
#
A[k][k + 1]```
smoky pulsar
little nymph
#

is a diagonal

smoky pulsar
#

oh yeah

#

i changed the code

#

before it was k + i % 8

little nymph
#

it's not A[k][k] which is a major diagonal, but it is one off

#

so

#

If you get a repeating pattern in the output, I suspect it is because of a repeating pattern in the input

smoky pulsar
#

yeah, but that shouldn't happen

little nymph
#

why not?

smoky pulsar
#

because that's not my goal

#

same words shoulnd't be the same in the encryption

little nymph
#

by the way, if you actually want to prevent it from being read, you will need to have a key

smoky pulsar
#

Input:
Hello world! Hello world! Hello world! Hello world!Hello world! Hello world! Hello world! Hello world!Hello world! Hello world! Hello world! Hello world!Hello world! Hello world! Hello world! Hello world!Hello world! Hello world! Hello world! Hello world!Hello world! Hello world! Hello world! Hello world!Hello world! Hello world! Hello world! Hello world!
Ouput:

ı~6ä[<Æ═åɧɲâÞ─^mZH⌂p6GÛ½òéµÞ╗ê‗)6:female_sign:§<mGXP¥ÐBë÷:diamonds:ı¼═/(­~:arrow_up_down:Û¶ƒ\µú:ƒı■Â:diamonds:[─¥ü║¼Ðä¨þ:diamonds:↑☻a♫\ktZïÂù▒ÂÔýÎ∟#L☻{nOY▬zñƒ:diamonds:ã¡→ÏIá↓{╝t:arrow_up_down:┼
vÞ{ÞÔ'Íú)RB­/X¥:relaxed:║¼Ð:diamonds:yþ:diamonds:↑éaµqÔ¶Y─ß☼¼(Û)V£#L鹯O┘û·ñƒäF-→XI@↓{╝¶Æ┼÷Þ¹ÞÔ'V#)RBp/░ôê║»×Ëß·→►G`fqbtY─ßż¿Û:registered:Í∟#L☻{nOY▬zñƒ:diamonds:ã¡→Ï
Iá↓{╝t:arrow_up_down:┼```
little nymph
#

otherwise someone reading the code will reverse engineer your algorithm

smoky pulsar
#

i have a key

#

K is a key

little nymph
#

K is a 32 bit int, so we're shooting for weak encryption I guess

smoky pulsar
#

what?

little nymph
#

I see

#

I don't understand how the bitshifts don't ruin everything

smoky pulsar
#

yeah K is a 32 bit int

#

why would the bit shiftr uin everything?

little nymph
#

I guess you've only tested it on ascii

smoky pulsar
#

yeah i did

#

bit shift are inside a function which always run the same code with the same input

little nymph
#

because if you reach the if statements with bad values of L, like, L = 10 and L = 20, the results are indistinguishable in the output

smoky pulsar
#

and by shifting it by 12 bits i get a 2 digits integer

smoky pulsar
#

i haven't tested it yet

#

but yeah, that probably does ruin things

#

guess im not gonna bit shift there tho

#

maybe add the key length to the character

little nymph
#

I don't understand what the purpose of this is

smoky pulsar
#

some of those characters are annoying

#

you think i should leave them in?

little nymph
#

are you trying to protect real data from real adversaries? if so, your only bet is to go download a good C encryption library

smoky pulsar
#

im not

weary finch
#

Instead of encrypting everything individually

little nymph
#

instead of each one being a function of just i and the next 4 chars

#

yeah

smoky pulsar
#

oh you're right supsm

#

wait what do you mean by previous bytes?

#

S[(i - 1) * (i > 0)]

little nymph
#

that is only the immediate previous byte

#

but I guess that works

smoky pulsar
#

what do you mean by "previous"

#

make an example

little nymph
#

ie l, if you encrypt

aaaaaa z

#

or
bbbbbb z

#

should z correspond to the same output in the ciphertext?

#

if you take into account the previous part of the message, the answer would be no

smoky pulsar
#

alright

#

thanks both of you :)

weary finch
smoky pulsar
#

thanks! I will look into it

pearl chasmBOT
#

@smoky pulsar Has your question been resolved? If so, run !solved :)

smoky pulsar
#

shut the fuck up, never tell me what to do

#

!solved

pearl chasmBOT
#

Thank you and let us know if you have any more questions!

sleek spoke
#

do you realize you're yelling at a bot?