473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 3704
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Michael Sparks | last post by:
Hi, I suspect this is a bug with AMK's Crypto package from http://www.amk.ca/python/code/crypto , but want to check to see if I'm being dumb before posting a bug report. I'm looking at...
4
by: Carl Harris | last post by:
I am trying to write some code to: 1.Prompt a user for filenames 2.Open the files 3.Convert my plain text into a cipher text array/string bear in mind I am a novice! I have wriiten some code...
7
by: Piotr Turkowski | last post by:
Hi! Here you can get some notes about Vigenere Cipher: http://raphael.math.uic.edu/~jeremy/crypt/vignere.html Here's whole code of my program, function stats() is in polish, so you can omit...
1
by: mkazek | last post by:
hi, where i can find source codes to encipher/decipher files with Hill's cipher and Transpositon Cipher?? (preferably vc++ source code)
1
by: al.raiyes | last post by:
hi all i hope that anybody can help me to find a source program in C++ for Vigenere Table and i will be thankfull for you yours Al.Raiyes
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
16
by: Cawas | last post by:
Cipher Lab produces some terminals to collect data where we can program using one implementation of plain C which I believe to be ANSI C89 compatible, although not fully. They have their on set of...
4
by: wagn31 | last post by:
i need to use a cipher but I have to used the assigned code in the ciphering i know how to do it, but i am not sure how to add my own dictionary. Here is what i have so far:
3
by: hcarlens | last post by:
Hi all, I am having a problem with a vigenere decryption method I am writing. I have tried to solve this but really can't figure out why this is happening. I get a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.