Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    transposition cipher - very urgent!

    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..

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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
    Code:
    <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>
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •