473,545 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ->
(*(^%&^GHJBBVvk ek)
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 3712
"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 ->
(*(^%&^GHJBBVvk ek)
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.
"Correctnes s" 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 ->
(*(^%&^GHJBBVvk ek)
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 ->
(*(^%&^GHJBBVvk ek)
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(AL PHA);

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.ne tcom.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
6558
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 using this library and to familiarise myself writing small tests with each of the ciphers. When I hit Crypto.Cipher.ARC4 I've
4
8027
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 already which completes takes 1 and 2 but haven't got a clue with the conversion (task 3)
7
6818
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 it. The problem is that the encrypting function is not working correctly, so I didn't write decryptying function. Plz, can you help me with both...
1
5419
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
2508
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
7268
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 as possible from users, so we encourage you to test the algorithm and send us your opinion. We would also like to receive enhancements and new...
16
3942
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 libraries as well, but all in all, it's basic C we're talking about. Ok, this is my first time on lots of things. I've never been to usenet, and...
4
10193
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
2247
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 java.lang.StringIndexOutOfBoundsException and while I know what this means, I don't know why it occurs in this instance. The method takes a ciphertext and key string as an...
0
7499
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7432
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7943
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7786
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6022
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.