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;
}
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!
Name:
Anonymous2013-10-24 17:41
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!
Name:
Anonymous2013-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:
Anonymous2013-10-24 22:35
And please remember to correctly indent your code. Nothing turns off another programmer like poor indentation.
Name:
L. A. Calculus!!wKyoNUUHDOmjW7I2013-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!!wKyoNUUHDOmjW7I2013-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.
You can't use the third element in an an array if there are only 2 elements in it.
Name:
Anonymous2013-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:
Anonymous2013-10-25 22:25
and stealing plaintext would be even better? =D
Name:
Anonymous2013-10-25 22:37
...or maybe not.. =)
Name:
Anonymous2013-10-25 22:43
pt[i] + pt[i+1] + key - ct[i] = ? ^^
Name:
Anonymous2013-10-25 23:27
...but only the second byte is weak?
so if you use two keys...?
Name:
Anonymous2013-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:
Anonymous2013-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!!wKyoNUUHDOmjW7I2013-10-26 0:19
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE GATOR OF DOOM! REPOST THIS 5 TIMES OR GET GATORED!!!
You should get rid of all those hashes at the beginning and end.
Name:
Anonymous2013-10-26 17:31
>le pedophile sage
Name:
Anonymous2013-10-26 19:24
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!
Name:
Anonymous2013-10-26 19:25
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!
Name:
Anonymous2013-10-26 19:25
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!
Name:
Anonymous2013-10-26 19:25
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!
Name:
Anonymous2013-10-26 19:26
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!
Name:
Anonymous2013-10-27 1:46
>─────▄████▀█▄
>───▄█████████████████▄
>─▄█████.▼.▼.▼.▼.▼.▼▼▼▼
>▄███████▄.▲.▲▲▲▲▲▲▲▲
>███████████████████▀▀
YOU HAVE BEEN CAUGHT BY THE NIGGER OF DOOM! REPOST THIS 5 TIMES OR GET NIGGERED!!!