Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to do vigenere cipher??
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nelsonkkyy




PostPosted: Tue Nov 10, 2009 4:29 pm   Post subject: How to do vigenere cipher??

What is it you are trying to achieve?

How to do vigenere cipher??

Can someone post a solution to help me plz?
Thank you
Sponsor
Sponsor
Sponsor
sponsor
DtY




PostPosted: Tue Nov 10, 2009 5:15 pm   Post subject: RE:How to do vigenere cipher??

Are you looking for a solution, or help?
If you just want help, you'll want to start with a simple caeser cipher. Once you get that, it should be relatively simple to apply a different one on each letter for the vigenere cipher.
nelsonkkyy




PostPosted: Tue Nov 10, 2009 5:49 pm   Post subject: RE:How to do vigenere cipher??

How to do a simple caeser cipher?!
i have no idea.
Tony




PostPosted: Tue Nov 10, 2009 5:51 pm   Post subject: RE:How to do vigenere cipher??

Wikipedia FTW -- http://en.wikipedia.org/wiki/Caeser_cipher
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nelsonkkyy




PostPosted: Tue Nov 10, 2009 5:55 pm   Post subject: RE:How to do vigenere cipher??

can some one make an example?
Dan




PostPosted: Tue Nov 10, 2009 6:02 pm   Post subject: RE:How to do vigenere cipher??

The wikipedia artical tony linked expilains it rather well but the pesdo code would be somthing like this:

code:

CipherText = ""

For letter x in PlainText
    y = (x + Key) mod 26
    append y to ChiperText
End



This assumes the letter x is repsented by a system such as A=0, B=1, C=3, .... Z=25. You can do this easly if you give some thought as to how chars are repesented in ASCII.

Note that the value of 'A' in ASCII is 65 and 'B' in ASCII is 66...... 'Z' is 90.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
nelsonkkyy




PostPosted: Tue Nov 10, 2009 6:16 pm   Post subject: RE:How to do vigenere cipher??

it does not work/.\
Tony




PostPosted: Tue Nov 10, 2009 6:29 pm   Post subject: RE:How to do vigenere cipher??

What do you mean it does not work?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
nelsonkkyy




PostPosted: Tue Nov 10, 2009 6:44 pm   Post subject: RE:How to do vigenere cipher??

the mod dosen't work
nelsonkkyy




PostPosted: Tue Nov 10, 2009 6:52 pm   Post subject: RE:How to do vigenere cipher??

can someone make a vigenere cipher example for me plz??
nelsonkkyy




PostPosted: Tue Nov 10, 2009 7:59 pm   Post subject: Re: RE:How to do vigenere cipher??

Dan @ Tue Nov 10, 2009 6:02 pm wrote:
The wikipedia artical tony linked expilains it rather well but the pesdo code would be somthing like this:

code:

CipherText = ""

For letter x in PlainText
    y = (x + Key) mod 26
    append y to ChiperText
End



This assumes the letter x is repsented by a system such as A=0, B=1, C=3, .... Z=25. You can do this easly if you give some thought as to how chars are repesented in ASCII.

Note that the value of 'A' in ASCII is 65 and 'B' in ASCII is 66...... 'Z' is 90.







SO how do i write like"a=0" for each letters
Dan




PostPosted: Tue Nov 10, 2009 8:23 pm   Post subject: RE:How to do vigenere cipher??

It's pseudocode and is not turing: http://en.wikipedia.org/wiki/Pseudocode

mod in this case means the modulo operation: http://en.wikipedia.org/wiki/Modulo_operation


If you look at an ASCII table ( http://www.asciitable.com/asciifull.gif )the capital letters values should look like this:

code:

A    65
B    66
C    67
D    68
E    69
F    70
G    71
.      .
.      .
.      .
Z    90


So if you where to say the value of a letter is X then X - 65 would get you:

code:

letter   value (x)      x - 65
A        65                0
B        66                1
C        67                2
D        68                3
E         69               4
F         70                5
G         71               6
.          .                  .
.          .                  .
.          .                  .
Z        90                 25



In turing you can covert a character to it's ASCII value with the ord command: http://compsci.ca/holtsoft/doc/ord.html

And you can convert an integer to it's conrpsonding character value with chr: http://compsci.ca/holtsoft/doc/chr.html



So the code for converting a character to a number such that A=0, B=1, C=2, .... Z=25 would look somthing like:

Turing:

x := ord(myChar) -65


and to convert it back:
Turing:

myChar := chr(x + 65)



Note that this only works for capital letters as lower case letter have diffrent values. If you want your chiper to handel both you will either have to convert them to upper case before encrypting or change how the chiper works to keep the case intack.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
nelsonkkyy




PostPosted: Tue Nov 10, 2009 8:36 pm   Post subject: Re: RE:How to do vigenere cipher??

Turing:

var plaintext,key,ciphertext:string

put "Enter a plaintext to encrypt"
get plaintext
put "Enter a key word"
get key

for i:1..length(plaintext)
ciphertext := ord(plaintext) -65

put ciphertext
%like that???%
Dan




PostPosted: Tue Nov 10, 2009 9:23 pm   Post subject: RE:How to do vigenere cipher??

Well thats a start, however there are some problems.


First "x := ord(myChar) -65" witch i posted is how to go from ascii code values of capaital letters to A=0, B=1, C=2, ... Z=25 type values. So you still need to use the key on the chipertext.

Also the ord command is used on characters and not strings.

Here is some code to work with:
Turing:

for i:1..length(plaintext)
   x := ord(plaintext(i)) -65
   % use key on x here
   % convert x back to a char
   % append x to chipertext string
end for


plaintext(i) Should return the character at index i in the string plaintext. So if "Hello World" was input and i was 2, it would be equal to 'e' (if i rember how string indexs in turing work correctly).

ord(plaintext(i)) converts the char from plaintext(i) to an integer (from the ASCII table).

Subtracting it by 65 bring it from A=65, B=66, ... Z=90 to A=0, B=1, ... Z=25.

The result is stroed in x (witch you need to declair some where above the for loop).


Give some thought to it and try to replace the comments with the correct code.


Also i should note that you are inputing key as a string. For this chiper the key is a integer, so you should either input an integer or convert the string to an integer.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
nelsonkkyy




PostPosted: Tue Nov 10, 2009 10:00 pm   Post subject: RE:How to do vigenere cipher??

can you send an example for me plz. I still can't do it. my email:nelsonmilk@hotmail.com
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: