468,168 Members | 1,510 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,168 developers. It's quick & easy.

Vigenere Cipher II - how to use files

Hi,
The code is here: http://free.ud.pl/~piotr/data/vigenere.zip
Its my program for decrypting and encrypting text.

Shot polish course:
szyfrowanie (szyfruj) - encrypting (text i want to code ->
(*(^%&^GHJBBVvkek)
odszyfrowanie (deszyfrowanie) - decrypting ( *^BNHJ*&% - > secret text)
obsluga plikow - using files

If you delete case 4 (obsługę plików) from the menu and the bad function
the program will work.

This is the problem. I don't know how to use files. I want to make a
function in which you will enter a path for incoming file and outgoing
file.

There are 4 possibilities:
1) you have entered both paths, the program will encrypt or decrypt text
from file_in to file_out
2) you have enetered path for file_in, the text will be encrypted or
decrypted and showed on display
3) you have entered path for file_out, the text will be taken from
keyboard and writted into file_out
4) no paths, the text will be got form keyboard and showed on display

In this function first I want to check if paths are correct.

If you understood me, please help me with this. I'm tired of this.

BTW:
How to enter a password, and show stars(*) on screen ?
How to make a decision in a menu without confirming it by enter?


--
Best Regards, Piotr Turkowski
http://www.elfiaknieja.tk/
Nov 14 '05 #1
9 3388
"Piotr Turkowski" <pi***@ust.tke.pl> wrote in message
news:c2**********@nemesis.news.tpi.pl...
Hi,
The code is here: http://free.ud.pl/~piotr/data/vigenere.zip
Its my program for decrypting and encrypting text.

Shot polish course:
szyfrowanie (szyfruj) - encrypting (text i want to code ->
(*(^%&^GHJBBVvkek)
odszyfrowanie (deszyfrowanie) - decrypting ( *^BNHJ*&% - > secret text)
obsluga plikow - using files

If you delete case 4 (obsluge plików) from the menu and the bad function
the program will work.

This is the problem. I don't know how to use files.

Where's your texbook? :-)
I want to make a
function in which you will enter a path for incoming file and outgoing
file.

There are 4 possibilities:
1) you have entered both paths, the program will encrypt or decrypt text
from file_in to file_out
2) you have enetered path for file_in, the text will be encrypted or
decrypted and showed on display
3) you have entered path for file_out, the text will be taken from
keyboard and writted into file_out
4) no paths, the text will be got form keyboard and showed on display
I'd probably approach it something like this
(not compiled or tested):

#include <stdio.h>

void func(const char *in_path, /* Pass NULL for stdin */
const char *out_path) /* Pass NULL for stdout */
{
FILE *in = in_path ? fopen(in_path, "r") : stdin;
FILE *out = out_path ? fopen(out_path, "w") : stdout;

if(in && out)
{
/* do your stuff */

if(in && in != stdin)
fclose(in);

if(out && out != stdout)
fclose(out);
}
else
{
/* could not open either input, output, or both.
Handle error. */
}

}

void callit(void)
{
func("inputpath", "outputpath"); /* case 1) */

func("inputpath", NULL); /* case 2) */

func(NULL, "outputpath"); /* case 3) */

func(NULL, NULL); /* case 4) */
}

Another possibility is to use an 'emtpy string' ("")
instead of NULL to indicate stdin and stdout, but
the idea is the same.

In this function first I want to check if paths are correct.
"Correctness" of a 'path name' is in the domain of your
operating system, so you'll need to check your documentation.

If by "correct" you mean does e.g. the input file exist
or the output file not exist, See the documentation for
the 'open mode' (second argument) of 'fopen()'. 'fopen()'
returns a NULL pointer upon failure, a non-NULL pointer
upon success. 'stdin' and 'stdout' are automatically
'open' at program startup (and don't try to close them! :-)).

If you understood me, please help me with this. I'm tired of this.

BTW:
How to enter a password, and show stars(*) on screen ?
Not possible with standard C. Perhaps your implementation
provides an extension for this. Consult your documentation.
How to make a decision in a menu without confirming it by enter?


Same answer as to the the first 'BTW' question.

HTH,
-Mike
Nov 14 '05 #2
Piotr Turkowski wrote:
Hi,
The code is here: http://free.ud.pl/~piotr/data/vigenere.zip
Its my program for decrypting and encrypting text.

Shot polish course:
szyfrowanie (szyfruj) - encrypting (text i want to code ->
(*(^%&^GHJBBVvkek)
odszyfrowanie (deszyfrowanie) - decrypting ( *^BNHJ*&% - > secret text)
obsluga plikow - using files
Seems to me that encryption is overkill :-)
BTW:
How to enter a password, and show stars(*) on screen ?
Cannot be done in standard C.
How to make a decision in a menu without confirming it by enter?


You are asking about reading a keypress. This cannot be done in standard
C. Please read the FAQ.

/david

--
"As a scientist, Throckmorton knew that if he were ever to break wind in
the echo chamber, he would never hear the end of it."

Nov 14 '05 #3
David Rubin wrote:
Seems to me that encryption is overkill :-)
I have never guessed what 'overkill' mean, but I think that you wanted
to say to me that it doesn't work. Here's version for you:
http://free.ud.pl/~piotr/data/pro.zip ;-)
You are asking about reading a keypress. This cannot be done in standard
C. Please read the FAQ.


I read... buuu :-(
--
Pozdrawiam, Piotr Turkowski
http://www.elfiaknieja.tk/
Nov 14 '05 #4
"Piotr Turkowski" <pi***@ust.tke.pl> wrote in message
news:c2**********@nemesis.news.tpi.pl...
David Rubin wrote:
Seems to me that encryption is overkill :-)


I have never guessed what 'overkill' mean,


"Overkill" means essentially the application of much
more and/or complex than necessary work and/or resources
to a problem. (e.g. using a shotgun to kill insects is
'overkill').

I'm not familiar with 'Vigenere Cipher', so I'm not
qualified to judge any code for it in that respect.

-Mike
Nov 14 '05 #5
Mike Wahler wrote:
"Piotr Turkowski" <pi***@ust.tke.pl> wrote in message
news:c2**********@nemesis.news.tpi.pl...
David Rubin wrote:
Seems to me that encryption is overkill :-)


I have never guessed what 'overkill' mean,

"Overkill" means essentially the application of much
more and/or complex than necessary work and/or resources
to a problem. (e.g. using a shotgun to kill insects is
'overkill').

I'm not familiar with 'Vigenere Cipher', so I'm not
qualified to judge any code for it in that respect.


In any case, it was a joke. Since I can't read Polish, your Polish phrases seem
well encrypted to me.

FWIW, IIRC, the Vigenere Cipher is a multi-level substitution cipher; basically
a table of different substitution ciphers. It can be cryptanalyzed relatively
easily using a modified letter frequency attack. Since we already know the
cleartext is in Polish in your application, you are at a significant disadvantage...

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
Nov 14 '05 #6
David Rubin wrote:
FWIW, IIRC, the Vigenere Cipher is a multi-level substitution cipher;
basically a table of different substitution ciphers. It can be
cryptanalyzed relatively easily using a modified letter frequency
attack. Since we already know the cleartext is in Polish in your
application, you are at a significant disadvantage...


Well, actualy it's not that easy. Original Vigenere Cipher is made of 26
alphabets, my one is made of 94 alphas.. If you wanna try, I can't
encrypt 10 letter fraze in my program, and you can try to decrypt it.

--
Pozdrawiam, Piotr Turkowski
http://www.elfiaknieja.tk/
Nov 14 '05 #7

"Piotr Turkowski" <pi***@ust.tke.pl> wrote in message
news:c2**********@nemesis.news.tpi.pl...
Hi,
The code is here: http://free.ud.pl/~piotr/data/vigenere.zip
Its my program for decrypting and encrypting text.

Shot polish course:
szyfrowanie (szyfruj) - encrypting (text i want to code ->
(*(^%&^GHJBBVvkek)
odszyfrowanie (deszyfrowanie) - decrypting ( *^BNHJ*&% - > secret text)
obsluga plikow - using files

If you delete case 4 (obsługę plików) from the menu and the bad function
the program will work.

This is the problem. I don't know how to use files. I want to make a
function in which you will enter a path for incoming file and outgoing
file.

There are 4 possibilities:
1) you have entered both paths, the program will encrypt or decrypt text
from file_in to file_out
2) you have enetered path for file_in, the text will be encrypted or
decrypted and showed on display
3) you have entered path for file_out, the text will be taken from
keyboard and writted into file_out
4) no paths, the text will be got form keyboard and showed on display

In this function first I want to check if paths are correct.

If you understood me, please help me with this. I'm tired of this.


Well you do have a problem here...

You have...

void szyfruj(){

int ii, c, i, s, p, npass, nnpass;
char *pass;
char ALPHA[94][94]={0};

wypelnij_tab(ALPHA);

printf("Podaj haslo: ");
gets(pass);
for (npass=0; pass[npass] != '\0';++npass); /* liczenie ilosci znakow */

....
}

Notice there is no storage allocated for 'pass'. Your code is crawling with this
error. Some compilers will let you get away with this so I can get...

/*
1. Szyfrowanie tekstu.
2. Deszyfrowanie tekstu.
3. Statystyka.
4. Obsluga plikow.
5. Zakonczenie programu.

Menu: 1
Podaj haslo: abc
Podaj tekst do zaszyfrowania:
Hello
+IQOS
*/

Others have commented on your 'overkill'. I take that to mean 'overly
complicated'.
Consider...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

enum DIR {EN, DE};
const char START = ' ', END = '~';

void cipher (const enum DIR);

int main (void) {

/* menu programu */
int menu;
for (;;) {
printf ("\n");
printf ("1. Szyfrowanie tekstu.\n");
printf ("2. Deszyfrowanie tekstu.\n");
printf ("3. Zakonczenie programu.\n");
printf ("\n\tMenu: ");
scanf ("%d", &menu);
getchar ();

switch (menu) {
case 1:
cypher (EN); /* ENcode */
break;
case 2:
cypher (DE); /* DEcode */
break;
case 3:
return 0;
default:
break;
}
}
}

void cipher (const enum DIR d) {
const int len = END - START, pos = d ? len : 0;
char pass[40], *p;
int c;

printf ("Podaj haslo: ");

fgets (pass, sizeof pass, stdin);
/* May include a newline ('\n') */

p = strchr (pass, '\n');
if (p)
/* Lose the newline ('\n') */
*p = '\0';
p = pass;

printf ("Podaj tekst:\n");

while ((c = getchar ()) != '\n')
if (c >= START && c <= END) {
const int i = pos - *p + START;
printf ("%c", (abs (i) + c - START) % len + START);
if (!*++p)
p = pass;
}
else
printf ("%c", c);
putchar ('\n');
}

/*
1. Szyfrowanie tekstu.
2. Deszyfrowanie tekstu.
3. Zakonczenie programu.

Menu: 1
Podaj haslo: abc
Podaj tekst:
Hello
+IQOS

1. Szyfrowanie tekstu.
2. Deszyfrowanie tekstu.
3. Zakonczenie programu.

Menu: 2
Podaj haslo: abc
Podaj tekst:
+IQOS
Hello
*/

Pardon my Polish!

Regards

Brian



Nov 14 '05 #8

"Brian MacBride" <ma******@ix.netcom.com> wrote in message
news:c2*************@ID-26770.news.uni-berlin.de...


#define cypher cipher

B

Nov 14 '05 #9
03 Mar 2004 17:47 -0500, David Rubin <no****@nowhere.net> wrote:
Mike Wahler wrote:
"Piotr Turkowski" <pi***@ust.tke.pl> wrote in message
news:c2**********@nemesis.news.tpi.pl...
David Rubin wrote:

Seems to me that encryption is overkill :-)

I have never guessed what 'overkill' mean,

"Overkill" means essentially the application of much
more and/or complex than necessary work and/or resources
to a problem. (e.g. using a shotgun to kill insects is
'overkill').

I'm not familiar with 'Vigenere Cipher', so I'm not
qualified to judge any code for it in that respect.


In any case, it was a joke. Since I can't read Polish, your Polish phrases seem
well encrypted to me.

FWIW, IIRC, the Vigenere Cipher is a multi-level substitution cipher; basically
a table of different substitution ciphers. It can be cryptanalyzed relatively
easily using a modified letter frequency attack. Since we already know the
cleartext is in Polish in your application, you are at a significant disadvantage...

/david


if you make a XOR first of "vigenere" ?

Nov 14 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Michael Sparks | last post: by
4 posts views Thread by Carl Harris | last post: by
7 posts views Thread by Piotr Turkowski | last post: by
1 post views Thread by mkazek | last post: by
1 post views Thread by al.raiyes | last post: by
2 posts views Thread by Julio C. Hernandez Castro | last post: by
16 posts views Thread by Cawas | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.