Results 1 to 2 of 2
  1. #1
    ssk2659 is offline Member
    Join Date
    Jan 2015
    Posts
    48
    Rep Power
    0

    Default Vineger encryption

    Hey folks, I've been having a project with Caesar cipher and Vinegere cipher. I already figured out Caesar one but I'm struggling with Vineger cipher. My encryption code is divided into two parts: encrypt() and encrypt1(). encrypt() method extracts every character and passes it to encrypt1()where all of the encryption takes place basically. I did here the code but it's not giving me any good results. For example, if
    Java Code:
    new VigenereCipher("SLIME").encrypt("GREEN")
    where "SLIME" is a key password and "GREEN" is the String which should be encrypted as YcMQR. But my code gives something like this ?&|{. Consider that the alphabet object covers everything = `"
    Java Code:
    ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 1234567890!@#$%^&*()_+-=[]{}\\|;:'\",./?<>
    "` Could please smb help me with that? Thanks in advance!

    Java Code:
      public class VigenereCipher extends SymmetricCipher {
        	
        	protected String password;
        	protected int passwordPos;
        	
        	public VigenereCipher(String password, Alphabet alphabet)
        	{
        		super(alphabet);
        		this.password = password;
        	}
        	public VigenereCipher(String password)
        	{
        		super(Alphabet.DEFAULT);
        		this.password = password	;
        	}
        	
        	public String getPassword()
        	{
        		return this.password;
        	}
        	
        	
        	
        	public String encrypt(String s)
        	{
        		passwordPos = 0;
        		String encrypted = "";
        		for(int i = 0; i < s.length(); i++)
        		{
        			char c = s.charAt(i);
        			encrypted += encrypt1(c);
        			
        		}
        		
        		
        		return encrypted;
        	}
        	
        	protected char encrypt1(char c)
        	{
        		//Alphabet temp = new Alphabet(s);
        		int index = 0;
        		char result = 0;
        		
        		index = alphabet.indexOf(c); //Found index of a character 
        		
        		if(index != -1)
        		{
        			int keyIndex = alphabet.get(passwordPos++ % password.length());
        			result = alphabet.get((keyIndex + index) % alphabet.length());
        		}
        		else 
        			throw new NotInAlphabetException(c, alphabet);
        		return result;
        	}
        	
        	public String decrypt(String c)
        	{
        		return c;
        	}
        	
        	protected char decrypt1(char c)
        	{
        		return c;
        	}
        	
        	public String toString()
        	{
        		return "Vigenere Cipher (password =\'"+this.password+"\')"; 
        	}
        	
        	
        
        }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Vineger encryption

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Encryption
    By dougie1809 in forum New To Java
    Replies: 4
    Last Post: 01-30-2012, 09:53 PM
  2. AES encryption
    By syst3mboot in forum Advanced Java
    Replies: 0
    Last Post: 09-05-2011, 01:52 AM
  3. Encryption
    By Martin1512 in forum Advanced Java
    Replies: 0
    Last Post: 05-02-2011, 07:25 PM
  4. How to encryption?
    By JavaCy in forum Advanced Java
    Replies: 1
    Last Post: 09-26-2010, 08:49 PM

Posting Permissions

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