...

View Full Version : transposition cipher - very urgent!



penepepe
11-04-2006, 11:02 AM
hi there!
i'm very new to java and i'm having a very hard time with an assignment, i hope that somebody can help..
here's what i've been asked:

A transposition cipher first chooses a key to number the columns, then write a plaintext in rows, and finally reads
the ciphertext by columns, staring with the column whose key letter is the lowest alphabetically. Shown below is
one example whereby a string ‘jamesbond’ is used as the key:

j amesbond

(5)(1)(6)(4)(9)(2)(8)(7)(3)
plaintext :

s e n d o n e send one million euros to my swiss
mi l l i on e bank account
uros to m
y s w i s s b ciphertext :

EIR NTOOTSCG EMBUADLSW
YSMUYANNLOSK E OINNOSCH
I IAE

Write a program TranspositionCipher.java that reads a key from the keyboard and a plaintext from a file
plain.txt, then displays the ciphertext. The plain.txt may contain multiple lines with lower case letters and
spaces. A sample of plain.txt is provided on the com6470 webpage, however your code should be able to handle
other input files. The ciphertext should be displayed on the screen using upper case letters and spaces. A key is a
sequence of lower case letters only, and any letter cannot appear more than once. If there is more than one space
left in the final row, they should be filled in with randomly generated lower case letters before encryption.


i have no idea how to do this, i only started java 5 weeks ago! i would be grateful if someone could help..

brandonH
11-04-2006, 12:11 PM
just to let you know, this is a javascript forum, not java. the tow are very different.

but i would suggest that you look into toUpperCase() and toLowerCase() for changing the letters in the string.

as far as finding spaces and replacing them with a random alpha char


<script type=text/javascript>
function random(){
var randomChars=new Array('a','b','c','d','e','f','g','h','i');
var rand=Math.floor((Math.random() * randomChars.length));
return randomChars[rand];
}
var strn="the string you pass to it";
var strnL=strn.length;
i='0';
var strn2='';
while(i<strnL){
//alert(strn.charAt(i));
if (strn.charAt(i)==' '){strn2+=random();}
else{strn2+=strn.charAt(i);}
i++;}
//do what you want with the result here
document.write(strn2);
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum