C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
help with Caesar cipher ,thx thx thx(urgent) Posted by beetle17 on 20 Nov 2006 at 8:18 AM
This message was edited by beetle17 at 2006-11-20 8:31:30

This message was edited by beetle17 at 2006-11-20 8:24:43

l just learn C program not long time ago,it is too diffcult for me to write a cipher

(Plaintext : a nice day)
(Key : -3)
(Ciphertext : X kfZb aXv)

Cipher will accept commands from the user and perform the operations required by the commands. There are three different commands. Key command starts with "K1:"followed by a string as the key. Encryption command starts with "E1:" followed by the plaintext. Decryption command starts with "D1:" followed by the ciphertext to be decrypted. After the user inputs an encryption (or decryption) command, Cipher1 should encrypt the plaintext (or decrypt the ciphertext) using the key input by a previous key command, and print the results. The error message "key not found" should be printed if the user inputs an encryption or decryption command before a key command. If the user
inputs multiple keys, the latest key will be used in the following encryption/decryption operations. Below are two examples (underlined text is the input from the user, and italic text is the output of Cipher).
When the plaintext/ciphertext includes non-letter symbols, Cipher1 will ignore them.For example, a plaintext of "No. 2" is equivalent to "No".

Example I of Cipher:
K 1: 3
E 1: I like dogs
C i p h e r t e x t is < L olnh grjv >
D 1: L olnh grjv
P l a i n t e x t i s < I like dogs >
E 1: H e l l o
C i p h e r t e x t i s < Khoor >

Example II of Cipher:
E 1: I like dogs
K e y not found
K 1: -54
E 1: Hello
C i p h e r t e x t is < Fcjjm>
K 1: h h h h
Invalid K e y






Report
Re: help with Caesar cipher ,thx thx thx(urgent) Posted by beetle17 on 20 Nov 2006 at 8:33 AM
This message was edited by beetle17 at 2006-11-20 23:38:22


l am typeing a program about cipher ,
to make the result:
Example I of Cipher:
input K 1: 3
//P l a i n t e x t &#61453; i s < I &#61453; l i k e &#61453; d o g s >
input E 1: I &#61453; l i k e &#61453; d o g s
//Ciphertext is < L &#61453; o l n h &#61453; g r j v >
output D 1: L &#61453;o l n h g r j v
input K 1: h h h h
putput Invalid &#61453; K e y

where K1: , D1: ,E1: are 3 different command,
Key command starts with "K1:"followed by a string as the key.
Encryption command starts with "E1:" followed by the plaintext.
Decryption command starts with "D1:" followed by the ciphertext to be decrypted.

l want to ask how could l write to separate K1: , D1: ,E1:from the input string,to let make appling different function on different command.

l only write
#include<stdio.h>
#include<string.h>
main()
{
char sen[100], x[100],k[100];command[]={'sen[0]','sen[1]','sen[2]','\0'}
int i, key;
gets(sen);
switch(command[]){
case "K1:":
function A;
case "D1:":
function B;
case "E1:":
function C;
default:
printf(input error)
}
is it Ok?





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.