#Encoding and decoding a message.

86 messages · Page 1 of 1 (latest)

knotty walrus
#

Let's say that we are given a string: "abcdefg..." and the cipher says it is supposed to + 100 in value so a = 97 + 100 which is 197 which is Å. But let us say that there is such a letterthat gets encoded into \0, what should we do to avoid or deal with this problem? Since it may cut the decoding short as it is returning a the string shorter as it thinks that it has ended.

low coveBOT
#

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.

green fulcrum
#

\0 is 0

#

so if cypher is only adding, it's safe

#

problem may occur with 'del' character though

knotty walrus
#

if it does del

#

what do you suggest we do to deal with it?

green fulcrum
#

it will do del if original char value is 27, 27 is escape

#

so it's unlikely

#

also, they have the same effect I think

knotty walrus
#

**** Original input message:

As much as you can,
Even if you cannot shape your life as you want it,
at least try this:
as much as you can; do not debase it
in excessive contact with the world,
in the excessive movements and talk.

Do not debase it by taking it,
dragging it often and exposing it
to the daily folly
of relationships and associations,
until it becomes burdensome as an alien life.

Constantine P. Cavafy (1913)

**** Encrypted text lines:

~yPΩ↕||4ô½~ZTSy£Åà?'▓¥ºk½[q¥¼ àï3ÿù╤STOq«ôzüä╢╔á}╚&ì╟═tgtΓ:↨ZZ♣\M♠ÄÄü│9hT⌂z&ô├┤à┴/ßì↔
YMNa╚'è|½-╙ú~|S╕≥6±ƒûu÷┼]%▀N^{

**** Decoded text lines (should be identical to original input!):

As much as you can,
Even if you cannot shape your life as you want it,
at least try this:
as much as you can; do

green fulcrum
#

;compile

#include <stdio.h>

int    main(void)
{
    char test[10] = "testline\0";

    printf("%s\n", test);
    test[4] = 127;
    printf("%s\n", test);

    test[4] -= 100;

    printf("%s\n", test);
    return 0;
}
knotty walrus
#

this is the output i am getting, as you can see the \0 seem to be cutting it off

green fulcrum
#

your cypher seems broken

#

text has 'n' and spaces before but they don't break the program

knotty walrus
#

the cypher is one where it takes a pgm as a cypher

green fulcrum
#

?

knotty walrus
#

it is as intended, like we take an image and use such image to encode or decode a text

#

space is also taken into consideration

green fulcrum
#

show code pls

knotty walrus
green fulcrum
#

what if you try %127 instead of 255?

knotty walrus
#

same problem

#

same issue

green fulcrum
#

in both encryption and decryption ?

knotty walrus
#

yep

green fulcrum
#

I think I see the problem

#

you're treating the array as one longitudinal array

#

so it'll reach '0' on the 50th character

#

you're supposed to decouple your 0-2500 variable into two 0 50 variables

knotty walrus
#

wut

green fulcrum
#

ah wait

knotty walrus
#

i dont think that matters

#

let me send u a ss of the image to decode

#

we use this to decode it, so i just made it into an array to make it simpler to decode

#

instead of [][] just []

green fulcrum
#

yeah i see that now

knotty walrus
green fulcrum
#

I'm trying to figure out the issue there

#

but have u ran gdb ?

knotty walrus
#

what is gdb

green fulcrum
#

a debugger

knotty walrus
#

ñope

#

i am owrking on notepad

#

lol

green fulcrum
#

what happens when you remove that if (result < 0) {
result += 255;
}

knotty walrus
#

returns nonesense

green fulcrum
#

i dont understand why previous n and spaces get cyphered/decyphered correctly and this one would break the program

#

that's why I think the problem is elsewhere

knotty walrus
#

space as a ascii value

green fulcrum
#

i know

#

32

#

but you cyphered spaces before with the same algo

#

and it goes on

#

so why break there ?

knotty walrus
#

and there is also some other random value that added with some other value, equates to \0? no?

green fulcrum
#

oh wait

#

i'm dumb that's the purpose of the image

#

sometimes it equals 0

knotty walrus
#

yesh yesh

green fulcrum
#

okok

#

so let's say it's inevitable to sometimes have a char value of 0, or del

#

you don't want to see that happen

#

so don't use ascii

knotty walrus
#

bruh

green fulcrum
#

oh you have no other choice

#

well well

knotty walrus
#

its ok, i will just wait for someone else to enlighten me

green fulcrum
#

good luck on that, I'll think about the problem for a bit

#

well

#

are you allowed to modify the values of passArr

knotty walrus
#

no

green fulcrum
#

you sure ? technically creating a passArr is some kind of improvisation

#

I dont see why you could not push it a bit further

knotty walrus
#

the image you enter is like a token or key

#

you cannot really go around changing the key itslef

green fulcrum
#

I understand that but I meant inside the functions

#

like, modify the interpretation of the image

knotty walrus
#

yesh

green fulcrum
#

anyway you could secure an algoritm that ensure a certain value range

#

not sure about the 128-255 range but if they're all printable make sure it's in there ?

#

you could also go between 33 and 126

#

so you modulo 93 and do + 33

#

and go the opposite way in decypher

low coveBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.