| |
 |
|
|
Science Forum Index » Cryptography Forum » sci.crypt Sanbox here i am ;)
Page 1 of 2 Goto page 1, 2 Next
|
| Author |
Message |
| JT |
Posted: Fri Jan 02, 2004 7:00 pm |
|
|
|
Guest
|
#include <stdio.h>
#include <io.h>
ordered[256];
reversed[256];
streamout[256];
void printout()
{
printf("\n**************************************************************************");
printf("\n*
*");
printf("\n* STREAMBUDDY a cipher by JT [Turbo C 2.01]
*");
printf("\n* (The code looks funny i know but it works mainthing?
*");
printf("\n* Buddy variable sized cipher, key 1>-256 bytes, int state
4096-bits *");
printf("\n* Key is expand into two streams, each run a keybased
shuffle 256bytes *");
printf("\n* Every round the shuffle are dowmmixed to 1 stream with a
saved state *");
printf("\n* Stream A xor B-> xor mixpad ->xor
streamout[savedstate]->xor plaintxt *");
printf("\n* A zero filled 102 MB file called plain.txt is created at
start +-1min *");
printf("\n*
*");
printf("\n* The encoded file cipher.txt, and the decoded file
decipher.txt +-1min *");
printf("\n*
*");
printf("\n**************************************************************************");
printf("\n\n\n");
}
/*PRNG*/
int streambuddy()
{
int mixpad[256];
int slot_1,slot_2,slot_3,slot_4;
int i,j,k;
int q=0;
for(i=0;i<255;i++)
{
slot_1 = ordered[i+1];
slot_2 = ordered[slot_1];
ordered[slot_1] = ordered[i];
ordered[i] = slot_2;
slot_3 = reversed[i+1];
slot_4 = reversed[slot_3];
reversed[slot_3] = reversed[i];
reversed[i] = slot_4;
}
for(i=0;i<256;i++)
{
mixpad[i] = reversed[i] ^ ordered[i];
}
for(i=0;i<256;i++)
{
streamout[i] ^= mixpad[i];
}
return streamout;
}
/*KEYXPAND*/
int keyexpander(int key[], int keysize)
{
int serie[256];
int i=0,j=0,k=0;
int stop=0;
int found=0;
for(i=0;i<256;i++)
{
stop=0;
while(!stop)
{
found = 0;
for(k=0;k<i;k++)
{
if(key[j]==serie[k]){found=1;}
}
if(!found)
{
serie[i]=key[j];stop=1;
} else
{
key[j] = key[j]+1;
}
if(key[j] > 255) {
key[j]=0;
}
}
j++;
if(j > keysize-1) {j=0;}
}
for(k=0;k<42;k++)
{
for(i=0;i<255;i++)
{
int slot_1,slot_2;
slot_1 = serie[i+1];
slot_2 = serie[slot_1];
serie[slot_1] = serie[i];
serie[i] = slot_2;
}
}
for(i=0;i<256;i++)
{
ordered[i]=serie[i];
}
return ordered;
}
int ireverse()
{
int i;int j=0;
for(i=255;i>-1;i--)
{
reversed[j] = ordered[i];
j++;
}
for(i=1;i<255;i++){
}
return reversed;
}
int main(int argc, char* argv[]){
printout();
encrypt();
decrypt();
}
int saltIV(int keyread[]){
int i;int seed;
srand(clock());
for (i=0;i<4;i++){
keyread[i]=rand()%256;
}
return keyread;
}
int decrypt()
{
int keyread[256];
int text[256];
int keysize=0;
int di,i,j,k;
FILE* in;
FILE* out;
char c;
printf("\n\n\nInput password for decode: ");
keysize=4;
in=fopen("cipher.txt","rb");
/*GET KEY SALTIV+PASSWD*/
for(i=0;i<4;i++){keyread[i]=getc(in);}
while ((keyread[keysize]=getchar())!=10){keysize++;}
printf("\n\nIV+password:");
for(i=0;i<keysize;i++){printf("%d",keyread[i]);printf(",");}
/*EXPAND KEY AND CREATE REVERSED SHADOW*/
keyexpander(keyread,keysize);
ireverse();
/*MAKE SURE ARRAY DONT GET FUCKED UP*/
for(i=0;i<256;i++){
streamout[i]=0;
}
printf("\n\n\nWait while decrypt 102 MB to disk...+-1min");
/*DECRYPT FILE*/
out=fopen("decipher.txt","wb");
for(k=0;k<20;k++){
for(j=0;j<20000;j++){
streambuddy();
for(i=0;i<256;i++){
text[i]=getc(in);
text[i]^=streamout[i];
fputc(text[i],out);
}
}
}
fclose(in);
fclose(out);
printf("\n\n\nFINISHED!!");
}
int encrypt()
{
int keyread[256];
int text[256];
int keysize=0;
int di,i,j,k;
FILE* in;
FILE* out;
char c;
/*CREATE ZEROFILLED PLAINTEXT*/
printf("\n\n\nWait!! while 102 MB zerofilled plaintext created
+-1min");
out=fopen("plain.txt","wb");
for(k=0;k<20;k++){
for(j=0;j<20000;j++)
{
for(i=0;i<256;i++)
{
fputc('0',out);
}
}
}
fclose(out);
out=fopen("cipher.txt","wb");
keysize=4;
/*CREATE KEY ->IV+PASSWORD*/
saltIV(keyread);
printf("\n\n\nInput password for encode:");
for(i=0;i<4;i++){fputc(keyread[i],out);}
while ((keyread[keysize]=getchar())!=10){keysize++;}
printf("\n\nIV+password:");
for(i=0;i<keysize;i++){printf("%d",keyread[i]);printf(",");}
/*EXPAND KEY AND CREATE REVERSED SHADOW*/
keyexpander(keyread,keysize);
ireverse();
for(i=0;i<256;i++){streamout[i]=0;}
/*ENCRYPT FILE*/
in=fopen("plain.txt","rb");
printf("\n\n\nWait while encrypt 102 MB to disk...+-1 min");
for(k=0;k<20;k++){
for(j=0;j<20000;j++){
streambuddy();
for(i=0;i<256;i++){
text[i]=getc(in);
text[i]^=streamout[i];
fputc(text[i],out);
}
}
}
fclose(in);
fclose(out);
} |
|
|
| Back to top |
|
| Arthur J. O'Dwyer |
Posted: Fri Jan 02, 2004 7:00 pm |
|
|
|
Guest
|
On Fri, 2 Jan 2004, JT wrote:
(Sorry in advance if I'm feeding a troll.)
Quote: ordered[256];
reversed[256];
streamout[256];
int streambuddy()
{
streamout[i] ^= mixpad[i];
return streamout;
}
Did you even *try* to compile this code before posting it?
And why did you post it anyway? Looking for comments? I hear
that somebody's set up a "sci.crypt sandbox" somewhere on the
WWW; maybe you should try posting this there, once you get it
to work.
-Arthur |
|
|
| Back to top |
|
| Arthur J. O'Dwyer |
Posted: Fri Jan 02, 2004 7:00 pm |
|
|
|
Guest
|
On Fri, 2 Jan 2004, JT wrote:
(Sorry in advance if I'm feeding a troll.)
Quote: ordered[256];
reversed[256];
streamout[256];
int streambuddy()
{
streamout[i] ^= mixpad[i];
return streamout;
}
Did you even *try* to compile this code before posting it?
And why did you post it anyway? Looking for comments? I hear
that somebody's set up a "sci.crypt sandbox" somewhere on the
WWW; maybe you should try posting this there, once you get it
to work.
-Arthur |
|
|
| Back to top |
|
| Joe Peschel |
Posted: Sat Jan 03, 2004 1:45 am |
|
|
|
Guest
|
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401022233150.8071@unix48.andrew.cmu.edu:
Quoted partial code removed.
Quote:
Did you even *try* to compile this code before posting it?
There were a few mistakes in the printf statements probably caused during
posting. I fixed them, and compiled the code without error, but a half-
dozen or so warnings.
Quote: And why did you post it anyway? Looking for comments?
Sheesh why not? :-)
Quote: I hear
that somebody's set up a "sci.crypt sandbox" somewhere on the
WWW; maybe you should try posting this there, once you get it
to work.
But it does work.
J
--
__________________________________________
When will Bush come to his senses?
Joe Peschel
D.O.E. SysWorks
http://members.aol.com/jpeschel/index.htm
__________________________________________ |
|
|
| Back to top |
|
| Joe Peschel |
Posted: Sat Jan 03, 2004 1:45 am |
|
|
|
Guest
|
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401022233150.8071@unix48.andrew.cmu.edu:
Quoted partial code removed.
Quote:
Did you even *try* to compile this code before posting it?
There were a few mistakes in the printf statements probably caused during
posting. I fixed them, and compiled the code without error, but a half-
dozen or so warnings.
Quote: And why did you post it anyway? Looking for comments?
Sheesh why not? :-)
Quote: I hear
that somebody's set up a "sci.crypt sandbox" somewhere on the
WWW; maybe you should try posting this there, once you get it
to work.
But it does work.
J
--
__________________________________________
When will Bush come to his senses?
Joe Peschel
D.O.E. SysWorks
http://members.aol.com/jpeschel/index.htm
__________________________________________ |
|
|
| Back to top |
|
| Arthur J. O'Dwyer |
Posted: Sat Jan 03, 2004 10:17 am |
|
|
|
Guest
|
On Sat, 3 Jan 2004, Joe Peschel wrote:
Quote:
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote...
Quoted partial code removed.
Did you even *try* to compile this code before posting it?
There were a few mistakes in the printf statements probably caused during
posting. I fixed them, and compiled the code without error, but a half-
dozen or so warnings.
snip
But it does work.
What language was it in, then? I thought it looked like it was
supposed to be C; that's why I said it didn't compile. If I was wrong,
I apologize (but I must flame the language designer for making it look
*so* *much* like C! :)
-Arthur |
|
|
| Back to top |
|
| Arthur J. O'Dwyer |
Posted: Sat Jan 03, 2004 10:17 am |
|
|
|
Guest
|
On Sat, 3 Jan 2004, Joe Peschel wrote:
Quote:
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote...
Quoted partial code removed.
Did you even *try* to compile this code before posting it?
There were a few mistakes in the printf statements probably caused during
posting. I fixed them, and compiled the code without error, but a half-
dozen or so warnings.
snip
But it does work.
What language was it in, then? I thought it looked like it was
supposed to be C; that's why I said it didn't compile. If I was wrong,
I apologize (but I must flame the language designer for making it look
*so* *much* like C! :)
-Arthur |
|
|
| Back to top |
|
| Richard Heathfield |
Posted: Sat Jan 03, 2004 1:21 pm |
|
|
|
Guest
|
|
| Back to top |
|
| Richard Heathfield |
Posted: Sat Jan 03, 2004 1:21 pm |
|
|
|
Guest
|
|
| Back to top |
|
| Joe Peschel |
Posted: Sat Jan 03, 2004 3:44 pm |
|
|
|
Guest
|
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401031515500.3676@unix42.andrew.cmu.edu:
Quote: What language was it in, then?
C.
J
--
__________________________________________
When will Bush come to his senses?
Joe Peschel
D.O.E. SysWorks
http://members.aol.com/jpeschel/index.htm
__________________________________________ |
|
|
| Back to top |
|
| Joe Peschel |
Posted: Sat Jan 03, 2004 3:44 pm |
|
|
|
Guest
|
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401031515500.3676@unix42.andrew.cmu.edu:
Quote: What language was it in, then?
C.
J
--
__________________________________________
When will Bush come to his senses?
Joe Peschel
D.O.E. SysWorks
http://members.aol.com/jpeschel/index.htm
__________________________________________ |
|
|
| Back to top |
|
| Arthur J. O'Dwyer |
Posted: Sat Jan 03, 2004 4:26 pm |
|
|
|
Guest
|
On Sat, 3 Jan 2004, Joe Peschel wrote:
Quote:
Richard Heathfield <dontmail@address.co.uk.invalid> wrote...
Joe Peschel wrote:
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote...
What language was it in, then?
C.
Not from where I'm standing.
Huh? You don't think it's C?
I had no problem compiling it, as I said, without any compilation errors
and only a handful of warnings, using Borland C.
Did any of those warnings have to do with the line
streamout[256];
which looks like it's supposed to declare an array 'streamout', but
doesn't say what type it is? Or with the line
return streamout;
which claims that 'streamout' is an 'int', even though the programmer
two lines earlier had tried to dereference it like an array?
I'm going to stop posting in this thread now, since my original
comment was a throwaway one meant to show the OP that his code was
broken, not one meant to start a "but MY compiler knows what <io.h>
means!" war.
Quote: http://users.powernet.co.uk/eton/misc/jt.c
Richard, your cleanup looks reasonable. I notice that the return
value of 'streambuddy' is never used, anyway. No comments on the
strength of the encryption, unfortunately, but a note that any
program that requires 100 MB of free disk space to encrypt an empty
file is probably ridiculous. :)
-Arthur |
|
|
| Back to top |
|
| Arthur J. O'Dwyer |
Posted: Sat Jan 03, 2004 4:26 pm |
|
|
|
Guest
|
On Sat, 3 Jan 2004, Joe Peschel wrote:
Quote:
Richard Heathfield <dontmail@address.co.uk.invalid> wrote...
Joe Peschel wrote:
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote...
What language was it in, then?
C.
Not from where I'm standing.
Huh? You don't think it's C?
I had no problem compiling it, as I said, without any compilation errors
and only a handful of warnings, using Borland C.
Did any of those warnings have to do with the line
streamout[256];
which looks like it's supposed to declare an array 'streamout', but
doesn't say what type it is? Or with the line
return streamout;
which claims that 'streamout' is an 'int', even though the programmer
two lines earlier had tried to dereference it like an array?
I'm going to stop posting in this thread now, since my original
comment was a throwaway one meant to show the OP that his code was
broken, not one meant to start a "but MY compiler knows what <io.h>
means!" war.
Quote: http://users.powernet.co.uk/eton/misc/jt.c
Richard, your cleanup looks reasonable. I notice that the return
value of 'streambuddy' is never used, anyway. No comments on the
strength of the encryption, unfortunately, but a note that any
program that requires 100 MB of free disk space to encrypt an empty
file is probably ridiculous. :)
-Arthur |
|
|
| Back to top |
|
| Joe Peschel |
Posted: Sat Jan 03, 2004 6:45 pm |
|
|
|
Guest
|
Richard Heathfield <dontmail@address.co.uk.invalid> wrote in
news:bt7iq8$1i7$1@sparta.btinternet.com:
Quote: Joe Peschel wrote:
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401031515500.3676@unix42.andrew.cmu.edu:
What language was it in, then?
C.
Not from where I'm standing.
Huh? You don't think it's C?
Quote:
I've cleaned it up so that it compiles cleanly under a nasty
suspicious set of gcc flags. You can find it at:
I had no problem compiling it, as I said, without any compilation errors
and only a handful of warnings, using Borland C.
Quote: http://users.powernet.co.uk/eton/misc/jt.c
Fixed the printf statements, eh? :-)
J
--
__________________________________________
When will Bush come to his senses?
Joe Peschel
D.O.E. SysWorks
http://members.aol.com/jpeschel/index.htm
__________________________________________ |
|
|
| Back to top |
|
| Joe Peschel |
Posted: Sat Jan 03, 2004 6:45 pm |
|
|
|
Guest
|
Richard Heathfield <dontmail@address.co.uk.invalid> wrote in
news:bt7iq8$1i7$1@sparta.btinternet.com:
Quote: Joe Peschel wrote:
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401031515500.3676@unix42.andrew.cmu.edu:
What language was it in, then?
C.
Not from where I'm standing.
Huh? You don't think it's C?
Quote:
I've cleaned it up so that it compiles cleanly under a nasty
suspicious set of gcc flags. You can find it at:
I had no problem compiling it, as I said, without any compilation errors
and only a handful of warnings, using Borland C.
Quote: http://users.powernet.co.uk/eton/misc/jt.c
Fixed the printf statements, eh? :-)
J
--
__________________________________________
When will Bush come to his senses?
Joe Peschel
D.O.E. SysWorks
http://members.aol.com/jpeschel/index.htm
__________________________________________ |
|
|
| Back to top |
|
| |
Page 1 of 2 Goto page 1, 2 Next
All times are GMT - 5 Hours
The time now is Thu Sep 04, 2008 11:29 pm
|
|