[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hey /g/, I'm a beginner in C and I made a one-time pad encryption

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 23
Thread images: 2

File: 1469415745942.gif (5KB, 500x500px) Image search: [Google]
1469415745942.gif
5KB, 500x500px
Hey /g/, I'm a beginner in C and I made a one-time pad encryption program and I wanna see if you can break it

LWe..N1..j3laIg?zU*QK.s!B05BbV4r?0F5n~}=y#@

I'll also post the source code, tell me if you see any problems, besides the fact it generates pseudo-random numbers
>>
#include <stdio.h>
#include <string.h>
#include <time.h>

main()
{
srand((unsigned) time(NULL));
char bstr[256];
printf("Message to XOR encrypt: ");
fgets(bstr, 256, stdin);
int i;
int key[sizeof(bstr)];
for(i = 0; i < strlen(bstr); i++)
{
key[i] = (rand() % 100);
bstr[i] = bstr[i] ^ key[i];
if(!isprint(bstr[i])) {bstr[i] = '.';}
}
printf("\n%s\n",bstr);
}
>>
File: #0001d6d461200000@650-650$75.jpg (57KB, 650x650px) Image search: [Google]
#0001d6d461200000@650-650$75.jpg
57KB, 650x650px
>>56072296
>One time pad
>Breaking
Jimbob! Get the pipe wrench!
>>
>>56072344
Yeah, I guess that was pretty retarded of me
>>
What's the point of encrypting something when you can't decrypt it afterwards
>>
>>56074518
It is more fun than just generating random numbers
>>
>>56072296
>I'm a beginner in C

Why the fuck are you using C over C++ for anything that doesn't involve ABIs?
>>
>>56074551
>yfw C ABI was never defined
>>
>>56074565
The C standard doesn't define an ABI because it's far too system-specific to be standardised, but they do go adding features that force implementations to break theirs.
>>
>>56072313
OMFG THAT'S A REVERSE ONE TIME PAD ENCRYPTION YOU MORON.
>>
>>56074551
It really doesn't matter when you're starting out seeing as c is a subset of c++ genius
>>
>>56072296
i just suffered a seizure because of that gif
>>
B..]Y`F.yBPI{FT
>>
>>56072296
Hey..g/..can you even.break this, faggots?.


Whoops haha
>>
>>56075189
Are you on windows?
>>
EQ{x/aSH.=i{O?gs=Fty.<RJ(Ae{R'M908 3_Dp!KTx.,$dH@]uB;3.Vq). .
>>
>>56072296
>HEY GUYS, GONNA INPUT COMPLETELY RANDOM LETTERS AND USE A KEY OF RANDOM DIGITS FOR YOU TO GUESS
fucking idiots. You need a pattern to crack things. Theres literally no way of confirming what you think is the key.
Things like this arent cracked, they are brute forced or the key is stolen from the servers. In this case you dont store the key so when the program terminates literally no one will be able to know what the key is. AKA useless encryption.
>>
>>56075493
As a matter of fact, I am.
>>
>>56075815
>if(!isprint(bstr[i])) {bstr[i] = '.';}
Shit way of doing this. You're ensuring that the encrypted string will get corrupted upon decryption.
>>
>>56072313
Everyone's already said, don't forget to solve the key distribution problem, which is the hardest part of one-time pad encryption.

>
for (i = 0; i < strlen(bstr); i++)

I thought this would cause buffer overflow if the input string is more than 255 bytes, but fgets inserts a null byte at the end of the buffer, so you're good.

>
key[i] = (rand() % 100);

>
if(!isprint(bstr[i])) {bstr[i] = '.';}

This should probably be mod 256, though o don't know of there are security problems with having the key be in a reduced range. But changing some of the ciphertext bytes after encryption is a surefire way to make sure the message won't get to your recipient intact. Either just output the bytes to stdout and let some other program deal with it, or do it I'm hex or base64.

Also, if you tell us exactly what time you ran this code, we could decipher it (except for the dots).
>>
>>56076112
>Also, if you tell us exactly what time you ran this code, we could decipher it (except for the dots).

You can assume he ran it within an hour of posting it, so you use his image timestamp.
for (x = timestamp; x > timestamp - 3600; i--)


It would be pretty much impossible to decipher without the source code though.
>>
>>56076197
Right, which I think someone already did:
>>56075189
>>
>>56072313
OP used the UNIX time in seconds to seed the standard C rand.

Presuming he generated this in the last 2-3 hours, this would be about 10000 instances to check.
Thread posts: 23
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.