| |
 |
|
|
Science Forum Index » Cryptography Forum » sci.crypt Sanbox here i am ;)
Page 2 of 2 Goto page Previous 1, 2
|
| Author |
Message |
| Richard Heathfield |
Posted: Sat Jan 03, 2004 11:40 pm |
|
|
|
Guest
|
Joe Peschel wrote:
Quote: "Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401032119160.5900@unix49.andrew.cmu.edu:
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,
Your original comment showed that you didn't know how to fix a few
posting- induced glitches in the guy's code.
Actually, I'm sure Arthur /does/ know how to do this. His original comment
was quite correct. Any C compiler is required to issue diagnostics for the
code as originally posted (even after fixing linewrapped string literals).
Quote: not one meant to start a "but MY compiler knows what <io.h
means!" war.
War? What are you talking about? You claimed the code wasn't C. I said it
was, and I compiled it.
In sci.crypt terms, it's probably verging on acceptable C (although it
really was very sloppy code). In a C newsgroup, it would not be considered
"real" C code, since it has so many problems that the language standard
does not require any implementation to translate it!
Frankly, though, I'd rather see unreadable and badly written C source than
unreadable and badly written <other language> source. :-)
I will leave the semi-fixed version of the code on my Website, at:
http://users.powernet.co.uk/eton/misc/jt.c
for at least a few days, to give anyone reading this thread the chance to
grab a copy that at least /compiles/. :-)
--
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton |
|
|
| Back to top |
|
| Joe Peschel |
Posted: Sun Jan 04, 2004 1:09 am |
|
|
|
Guest
|
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401032119160.5900@unix49.andrew.cmu.edu:
Quote: 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,
Your original comment showed that you didn't know how to fix a few posting-
induced glitches in the guy's code.
Quote: not one meant to start a "but MY compiler knows what <io.h
means!" war.
War? What are you talking about? You claimed the code wasn't C. I said it
was, and I compiled it.
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: Sun Jan 04, 2004 1:09 am |
|
|
|
Guest
|
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in
news:Pine.LNX.4.58-035.0401032119160.5900@unix49.andrew.cmu.edu:
Quote: 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,
Your original comment showed that you didn't know how to fix a few posting-
induced glitches in the guy's code.
Quote: not one meant to start a "but MY compiler knows what <io.h
means!" war.
War? What are you talking about? You claimed the code wasn't C. I said it
was, and I compiled it.
J
--
__________________________________________
When will Bush come to his senses?
Joe Peschel
D.O.E. SysWorks
http://members.aol.com/jpeschel/index.htm
__________________________________________ |
|
|
| Back to top |
|
| Strangely Placed |
Posted: Sun Jan 04, 2004 4:48 am |
|
|
|
Guest
|
[Joe - your article didn't make it to my news-swerver. I only found
the text by chasing up on Google, which is why I'm replying to it from
Google.]
Joe Peschel <jpeschel@no.spam.org> wrote in message news:<Xns9465B4136FB28fa0khgj7ji8i8jo9@216.168.3.44>...
Quote: Richard Heathfield <dontmail@address.co.uk.invalid> wrote in
news:bt7iq8$1i7$1@sparta.btinternet.com:
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?
Not in the sense that I use the word. I think of a C program as being
one that is acceptable to a conforming implementation when invoked in
conforming mode, and I don't think I've got any compilers that are
prepared to accept that code as written. I concede that this
definition is perhaps a little strict for sci.crypt subscribers! :-)
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.
I'm surprised at Borland. Did you invoke it in conforming mode?
Those and a bunch of stuff that your compiler really should have
warned you about - e.g. the return mechanisms were totally shot to
hell. I'm not saying it was a /huge/ amount of work. I think it took
me about five minutes. Feel free to do a diff to discover what's
changed.
--
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton |
|
|
| Back to top |
|
| JT |
Posted: Sun Jan 04, 2004 6:09 am |
|
|
|
Guest
|
/*Fixed the wraparound bug in the PRNG*/
/*and added code to slide the reversed*/
/*array out of phase.Thank you Richard*/
/* for cleanin up the sloopy code. */
/*If there is interest i have a bit */
/*substitution cipher using the same */
/*principles (slower) (safer?) */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int ordered[256];
int reversed[256];
int streamout[256];
void printout()
{
printf("\n******************************************************************");
printf("\n* *");
printf("\n* STREAMBUDDY a cipher in CTR mode by JT [Turbo C 2.01] *");
printf("\n* (The code looks funny i know but it works *");
printf("\n* Buddy scalable cipher, key 1>-256 bytes, int state 4096-bits *");
printf("\n* Key expand into 2 streams, each run a keybased shuffle256bytes*");
printf("\n* Shuffle blocks are dowmmixed to 1 stream with a saved state *");
printf("\n* Stream A xor B->mixpad->xorstreamout[savedstate]->xor plaintxt*");
printf("\n* A zero filled 102MB file plain.txt is created at start +-1min *");
printf("\n* *");
printf("\n* The encoded=cipher.txt, and the decoded=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;
for(i=0;i<256;i++)
{
if(i==256){
/*WRAPAROUND CASE*/
slot_1 = ordered[0];
slot_2 = ordered[slot_1];
ordered[slot_1] = ordered[i];
ordered[i] = slot_2;
slot_3 = reversed[0];
slot_4 = reversed[slot_3];
reversed[slot_3] = reversed[i];
reversed[i] = slot_4;
} else {
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 0;
}
/*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 0;
}
int ireverse()
{
int i;int j=0;int slot1;int slot2;
for(i=255;i>-1;i--)
{
reversed[j] = ordered[i];
j++;
}
/*A mechanism to make the reversed block out of phase*/
for(i=0;i<7;i++){
slot1 = reversed[i+1];
slot2 = reversed[slot1];
reversed[slot1] = reversed[i];
reversed[i] = slot2;
}
return 0;
}
int saltIV(int keyread[]){
int i;
srand(clock());
for (i=0;i<4;i++){
keyread[i]=rand()%256;
}
return 0;
}
int decrypt()
{
int keyread[256];
int text[256];
int keysize=0;
int i,j,k;
FILE* in;
FILE* out;
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!!");
return 0;
}
int encrypt()
{
int keyread[256];
int text[256];
int keysize=0;
int i,j,k;
FILE* in;
FILE* out;
/*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);
return 0;
}
int main(void){
printout();
encrypt();
decrypt();
return 0;
} |
|
|
| Back to top |
|
| Joe Peschel |
Posted: Mon Jan 05, 2004 2:27 am |
|
|
|
Guest
|
binary@eton.powernet.co.uk (Strangely Placed) wrote in
news:acec90c3.0401040148.6f0fabc9@posting.google.com:
Quote: [Joe - your article didn't make it to my news-swerver. I only found
the text by chasing up on Google, which is why I'm replying to it from
Google.]
Joe Peschel <jpeschel@no.spam.org> wrote in message
news:<Xns9465B4136FB28fa0khgj7ji8i8jo9@216.168.3.44>...
Richard Heathfield <dontmail@address.co.uk.invalid> wrote in
news:bt7iq8$1i7$1@sparta.btinternet.com:
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?
Not in the sense that I use the word.
I know you're an expert on this, Richard, but I think you're being overly
pedantic here. What you're saying amounts to: "if there are errors in your
C code, it isn't C.
That's almost the same as my claiming that the messages of MKS, TSD, and
DAS are not in English.
Here's another counter-example: (I'm really holding my breath on this one,
though)
#include <stdio.h>
main()
{
printf("Hey, Richard, I respectfully disagree\n");
}
Now, some compilers would give you a warning about this code. Is it C? I
think it is. Brian and Dennis seem to think it is, too.
So, even though you've probably heard this argument before, I think it's
better to call such source "C code that generates a warning," instead of
claiming it isn't C.
Quote: I think of a C program as being
one that is acceptable to a conforming implementation when invoked in
conforming mode, and I don't think I've got any compilers that are
prepared to accept that code as written. I concede that this
definition is perhaps a little strict for sci.crypt subscribers! :-)
I think it's a bit strict no matter the news group.
In sci.crypt, I am not that fussy about the Peschel-friendly Vigenère
cipher; for instance, I wouldn't say that a Vigenère that used the wrong
alphabet as the "A" alphabet was not a Vigenère. I'd say the tableau needed
correction. ;=<D
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.
I'm surprised at Borland. Did you invoke it in conforming mode?
http://users.powernet.co.uk/eton/misc/jt.c
Fixed the printf statements, eh? :-)
Those and a bunch of stuff that your compiler really should have
warned you about - e.g. the return mechanisms were totally shot to
hell. I'm not saying it was a /huge/ amount of work. I think it took
me about five minutes. Feel free to do a diff to discover what's
changed.
I thought I mentioned I got a half-dozen warnings, but no error messages.
à bientôt.
J
--
__________________________________________
When will Bush come to his senses?
Joe Peschel
D.O.E. SysWorks
http://members.aol.com/jpeschel/index.htm
__________________________________________ |
|
|
| Back to top |
|
| Richard Heathfield |
Posted: Mon Jan 05, 2004 8:31 am |
|
|
|
Guest
|
Joe Peschel wrote:
Quote: binary@eton.powernet.co.uk (Strangely Placed) wrote in
news:acec90c3.0401040148.6f0fabc9@posting.google.com:
I know you're an expert on this, Richard,
What do I say here? "Yes, you're right"? "Aw shucks"? or perhaps "I wish I
were"? Pick whichever you think is appropriate. :-)
Quote: but I think you're being overly
pedantic here. What you're saying amounts to: "if there are errors in your
C code, it isn't C.
That's almost the same as my claiming that the messages of MKS, TSD, and
DAS are not in English.
So we are in agreement, then? ;-)
Quote: Here's another counter-example: (I'm really holding my breath on this
one, though)
#include <stdio.h
main()
{
printf("Hey, Richard, I respectfully disagree\n");
}
Now, some compilers would give you a warning about this code. Is it C? I
think it is. Brian and Dennis seem to think it is, too.
I think it is, too. It is, in fact, a strictly conforming program (in the
Doug Gwyn sense of the word). The fact that a compiler issues a diagnostic
is not sufficient to make it "not a C program", since compilers may issue
diagnostics purely on a whim if they wish. The only marginally dodgy bit
about it is the lack of a return value from main(); since the program does
not rely on this for its output, this is a moot point from a program
conformance perspective. (Doug Gwyn will, no doubt, correct me if I'm
wrong!)
Quote:
So, even though you've probably heard this argument before, I think it's
better to call such source "C code that generates a warning," instead of
claiming it isn't C.
I do see your point. I just don't agree with it. :-)
Quote: I think of a C program as being
one that is acceptable to a conforming implementation when invoked in
conforming mode, and I don't think I've got any compilers that are
prepared to accept that code as written. I concede that this
definition is perhaps a little strict for sci.crypt subscribers! :-)
I think it's a bit strict no matter the news group.
In at least one newsgroup that I frequent, it would constitute a relatively
gentle crit of the code!
Quote: In sci.crypt, I am not that fussy about the Peschel-friendly Vigenère
cipher; for instance, I wouldn't say that a Vigenère that used the wrong
alphabet as the "A" alphabet was not a Vigenère. I'd say the tableau
needed correction. ;=<D
I wonder if I should check up on you via Google? :-)
Quote: Fixed the printf statements, eh? :-)
Those and a bunch of stuff that your compiler really should have
warned you about - e.g. the return mechanisms were totally shot to
hell. I'm not saying it was a /huge/ amount of work. I think it took
me about five minutes. Feel free to do a diff to discover what's
changed.
I thought I mentioned I got a half-dozen warnings, but no error messages.
Perhaps Borland noticed that the return values weren't actually used, and
thus didn't feel particularly fussed about diagnosing the types. It's
possible. After all, you got at least one diagnostic and that's all that is
required from the compiler by the Standard.
--
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton |
|
|
| Back to top |
|
| Douglas A. Gwyn |
Posted: Tue Jan 06, 2004 1:26 am |
|
|
|
Guest
|
Richard Heathfield wrote:
The only marginally dodgy bit
Quote: about it is the lack of a return value from main(); since the program does
not rely on this for its output, this is a moot point from a program
conformance perspective. (Doug Gwyn will, no doubt, correct me if I'm
wrong!)
Okay, it does matter. For C89, reaching the } is not allowed
for a function that returns non-void. For C99, that results
in an implicit return 0; but the return type of main was not
specified (no implicit int in C99). The program is not s.c.
and a conforming C implementation doesn't have to do anything
sensible with it. It could fail at compile time or at run time,
or it could be given some invented semantics, sane or otherwise.
But really, this sort of nit-picking isn't very useful in
sci.crypt, which is not about C programming except as a means
to an end. It would be useful for people to learn how to code
more portably, but the intended meaning of the program is clear
enough regardless of such technical errors. |
|
|
| Back to top |
|
| |
Page 2 of 2 Goto page Previous 1, 2
All times are GMT - 5 Hours
The time now is Thu Aug 21, 2008 3:39 pm
|
|