Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

An question about cesar's encryption

Name: Anonymous 2013-10-24 16:40

I'm doing some tests about encryption and I'm trying this one.
It's a small code and I'm having a little issue using the ASCII table.
I want to don't appear this strange chars.
http://puu.sh/4Yx30.png
What should i change?
Here's the code.

########################################################
#include <stdio.h>
#include <string.h>
#define TM 127
int main ()
{
char user [TM], userc[TM];
char pass [TM], passc[TM];
int key,len,tmax,ini,i;
tmax=125;
ini=40;

printf("Type a key: ");
scanf("%d", &key);

printf ("Type the user: \n");
scanf ("%s", &user);
len=strlen(user);

if (len<100){
    for (i=0;i<len;i++){
        if (user[i]+key>tmax){
        userc[i]=user[i]+key-ini;
        }
        else{
        userc[i]=user[i]+key;
        }
    }
//encrypted
printf("user: %s\n",userc);
}
system ("PAUSE");
return 0;
}

######################################

Name: Anonymous 2013-10-24 17:08

ENCRYPT MY ANUS

Name: Anonymous 2013-10-24 17:08

>>2
Haha, very funny, you idiot.

Name: Anonymous 2013-10-24 17:14

>─────▄████▀█▄
 >───▄█████████████████▄
 >─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
 >▄███████▄.▲.▲▲▲▲▲▲▲▲
 >███████████████████▀▀
 YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!

Name: Anonymous 2013-10-24 17:41



 >─────▄████▀█▄
   >───▄█████████████████▄
   >─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
   >▄███████▄.▲.▲▲▲▲▲▲▲▲
   >███████████████████▀▀
   YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!

Name: Anonymous 2013-10-24 22:34


if (len<100){
    for (i=0;i<len;i++){
        if (user[i]+key>tmax){
        userc[i]=user[i]+key-ini;
        }
        else{
        userc[i]=user[i]+key;
        }
    }
//encrypted
printf("user: %s\n",userc);
}

Why "<100"?
The problem is twofold:
1. You do not terminate the "userc" string (hint0: "asd" is the string {'a', 's', 'd', '\0'}) (hint1: '\0' terminates a string, note the single quotes) (hint2: i refers to the index just after the end of the string when the loop is complete)
2. You have that shitty pointless if-condition


Also:
system ("PAUSE");
Please don't do that, it's ugly to spawn a cmd.exe subprocess just to wait for a single keypress.

Name: Anonymous 2013-10-24 22:35

And please remember to correctly indent your code. Nothing turns off another programmer like poor indentation.

Name: L. A. Calculus !!wKyoNUUHDOmjW7I 2013-10-25 4:49

>>1
printf("Type a key: ");
YAINT CALLED fflush AND YAINT TERMINATED stdout WITH A NEW FUKIN LINE.

scanf ("%s", &user);
UR PASSING A 'char (*)[127]' INSTED OF A 'char *'.

if (user[i]+key>tmax){
UR REFERENCING A POTENTIALLY UNINITIALISED OBJECT.

DA FUNNY THING IS UR TRYING TO WRITE AN INTERACTIVE PROGRAM WHEN SUCH A DESIGN AINT EVEN NECESSARY, AND U DONT EVEN KNOW HOW TO DO DAT PROPERLY.

UR PROGRAMS WORSE THAN A BUNCH OF CONSTIPATED RUSSIANS TRYING TO SHIT ALL OVER EACH OTHER. GO REED K&R2 AND DA FUKIN STANDARD, DEN GET DA FUK OUT OF MY THRED, YA RETOID.

>>6-7
Please don't do that, it's ugly to spawn a cmd.exe subprocess just to wait for a single keypress.
And please remember to correctly indent your code. Nothing turns off another programmer like poor indentation.
GET UR ASS BAK 2 /fa/ YA CROSS-DRESSING SISSY.

Name: L. A. Calculus !!wKyoNUUHDOmjW7I 2013-10-25 4:51

>>1
AND YAINT SPECIFIED A MAXIMUM FIELD WIDTH FOR DA "%s" FORMAT SPECIFIER. I CUD GO ON BUT I THINK I COVERED DA BULK OF UR ERRORS.

Name: Anonymous 2013-10-25 5:43

                ♥  ♥           ♥  ♥
             ♥       ♥       ♥       ♥
            ♥           ♥  ♥           ♥
          ♥              ♥              ♥
         ♥                               ♥
        ♥                                  ♥
        ♥                                  ♥
       ♥                                   ♥
       ♥                                   ♥
       ♥                                   ♥
        ♥                                  ♥
        ♥              ∧∧∧∧              ♥
         ♥            (*゚ー゚)゚ー゚*)            ♥
          ♥           ノ  つと  ヽ           ♥
            ♥        ~(_つ と _)~        ♥
              ♥                       ♥
                ♥                    ♥
                  ♥                ♥
                   ♥            ♥
                     ♥         ♥
                       ♥      ♥
                             ♥

Name: Anonymous 2013-10-25 8:46

check 'em #2

Name: Anonymous 2013-10-25 10:11

'> DEN GET DA FUK OUT OF MY THRED, YA RETOID.

Name: Anonymous 2013-10-25 10:14

quiet down an fix your code, arthur =)

Name: Anonymous 2013-10-25 10:40

here's a start =D


const char[] alpha = "abcdefghijklmnopqrstuvwxyz";

int key = 0;

char* data;
char[] outp;

int main(int argc, char* argv){

  int i=0, j=0, k=0;
  if(argc==2){

    key = *(int) argv[1];

    data = argv[2];

    while(data[i]!='\0'){

      for(j=0;j>26;j++)

        k = k + (data[i]==alpha[j]) * j;

      outp[i] = alpha[(k + key) % 26];

      if(data[i]==' ') outp[i] = ' ';

      }
    }
  }

Name: Anonymous 2013-10-25 20:01

>  if(argc==2){

>    data = argv[2];

You can't use the third element in an an array if there are only 2 elements in it.

Name: Anonymous 2013-10-25 22:20

=) whoops, but i would've expected there are more mistakes.. ^^
it has no i++, or printf("%s\n", &outp[0])
kind of interestingly, without resetting k you get a mock CTS-mode cesar cipher (cipher-text stealing..), which kind of makes it slightly harder to break? =)

Name: Anonymous 2013-10-25 22:25

and stealing plaintext would be even better? =D

Name: Anonymous 2013-10-25 22:37

...or maybe not.. =)

Name: Anonymous 2013-10-25 22:43

pt[i] + pt[i+1] + key - ct[i] = ? ^^

Name: Anonymous 2013-10-25 23:27

...but only the second byte is weak?
so if you use two keys...?

Name: Anonymous 2013-10-25 23:57

And maybe a variable-length nonce? =D
Wonder how secure you can make a caesar cipher, using only a small secret key? (eg 2 key ints..) =) if you use the nonce as a temporary key...

Name: Anonymous 2013-10-26 0:07

enigma only used a 3-char key ^^ use the third to mark the end of the nonce?

Name: L. A. Calculus !!wKyoNUUHDOmjW7I 2013-10-26 0:19

>>14
const char[] alpha
WAT DA FUCK

char[] outp;
WAT DA FUCK

char* argv
WAT DA FUCK

key = *(int) argv[1];
WAT DA FUCK

AND I AM STOPPIN RIGHT FUCKIN DER.

BUY URSELF SOME CRAYONS AND STAY DA FUCK AWAY FROM C UNTIL U LERN TO THINK, YA FUCKIN JAKE ASSED KINDERGARTENER.

NOW GET DA FUK OUT OF MY THRED.

Name: Anonymous 2013-10-26 0:28

>>15
He can, if he wants to
argv[argc] == NULL

Name: Anonymous 2013-10-26 0:42


const char[] alpha = "abcdefghijklmnopqrstuvwxyz";

int key[4];

int tkey[12];

int nonce = rand(10) + 2;

char* data;
char[] outp;

int main(int argc, char* argv){

  int i=0, j=0, k=0, l=0, x=0;

  if(argc==2){

    data = argv[0];

    for(j=0;j<3;j++){

      key[j] = 0;

      for(l=0;l>26;l++)
        key[j] = key[j] + (data[i]==alpha[j]) * l;
      }

    for(j=0; j<nonce; j++){

      x = key[2];

      while(x != key[2])
     
        x = rand(26);

      tkey[j] = x;

      }

    tkey[j] = key[2];

    k = 0;

    for(j=0; j<=nonce; j++){

      k = (k + tkey[j] + key[j%2]) % 26;

      outp[j] = alpha[k];

      }

    data = argv[1];

    while(data[i]!='\0'){

      for(l=0;l>26;l++)

        k = k + (data[i]==alpha[l]) * l;

      outp[i + j] = alpha[(k + tkey[i%nonce]) % 26];

      if(data[i]==' ') outp[i] = ' ';

      i++;

      }
    }

   outp[i+j] = '\0';

   printf("%s\n", &outp[0]);

  }

Name: Anonymous 2013-10-26 1:15

Name: Anonymous 2013-10-26 1:16

now it just has runtime errors ^^

Name: Anonymous 2013-10-26 2:31

wqeus tjf tdpv rake vkq ?

Name: Anonymous 2013-10-26 2:38

hlypxgwmdx id npu x bfg =)

Name: Anonymous 2013-10-26 2:40

lgyyawyhjsudfoqzbkmvx

Name: Anonymous 2013-10-26 11:31

>>26
i bet it'd work in tcc =)

Name: Anonymous 2013-10-26 13:24

>─────▄████▀█▄
   >───▄█████████████████▄
   >─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
   >▄███████▄.▲.▲▲▲▲▲▲▲▲
   >███████████████████▀▀
   YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!

Name: Anonymous 2013-10-26 17:21

You should get rid of all those hashes at the beginning and end.

Name: Anonymous 2013-10-26 17:31

>le pedophile sage

Name: Anonymous 2013-10-26 19:24

>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!

Name: Anonymous 2013-10-26 19:25

>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!

Name: Anonymous 2013-10-26 19:25

>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!

Name: Anonymous 2013-10-26 19:25

>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!

Name: Anonymous 2013-10-26 19:26

>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!

Name: Anonymous 2013-10-27 1:46

>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!

Don't change these.
Name: Email:
Entire Thread Thread List