Caesar Cipher - Encode / Decode Message With Given Key
Nov 1, 2014
I have been assigned to make a program that encodes and decodes a given message with the given key (spaced numbers, for example: 3 1 7 4 2 5). I'll post the code for all the classes that I am using below.
QueueInterface:
import java.util.*;
public interface QueueInterface<T>
{
T dequeue() throws QueueUnderflowException;
boolean isEmpty();
[Code] ....
Ok, so the classes to focus on are these:
CircularLinkedUnbndQueue
CircularLinkedQueueITD
Encoder
Decoder
EncodeDecodeConsole
EncodeDecodeITD
Because those are the ones I had to write myself, the others were given to us to use. As far as these classes go, they work fine without causing any errors from the input I give. For example if I enter a message and a key, it correctly encodes and decodes the message with the given key. What I'd like for you fine programmers to do is give feedback on those 6 classes. Like, suggestions on how to make them better or more efficient, neater, changing any of the methods to make them more efficient or prevent any errors beforehand, etc.
View Replies
ADVERTISEMENT
Feb 13, 2014
how to decode a .jar file to view its methods and later encode it. i wanted to write the program in java instead of using winzip
View Replies
View Related
Apr 4, 2014
I was asked to write program in Java, that should code and encode some String in following way:
i) coding : "rrryyyyyaaaa" -> "r3y5a4"
ii) encoding: "r3y5a4" -> "rrryyyyyaaaa"
The code works fine, but I forgot the name of this coding method.
View Replies
View Related
Jan 28, 2015
I'm building casar cipher with using ASCII. I'm done changing lower and upper case alphabet, but I don't know how to fix my code for changing number 9 to <.
here is my class code.
public class SimpleMessageCipher implements MessageCipher {
public String encode(String plainText,int shiftKey){
String cipherText="";
for(int i=0;i<plainText.length();i++)
{
//stores ascii value of character in the string at index 'i'
int c=plainText.charAt(i);
[Code]...
View Replies
View Related
Jan 21, 2014
I'm trying to make a simple Caesar cipher that takes in a String as the first argument and a integer shift as the second argument. Namely, there appears to be a problem with the loop and how I have declared the array - I want the converted characters to be put into a new array called newCharacterArray, converted back to a String and displayed in the command prompt window.
public class Caesar {
public static void main(String inString, int k) {
System.out.println("String: " + inString);
char inStringArray[] = inString.toCharArray();
[code]....
View Replies
View Related
Feb 9, 2014
I have an assignment, similar to ones of seen in the past. The assignment is to take a users text input and to encrypt it using 3 different types of encryptions: Caesar, Transpose, and Reverser. The professor gave us the bulk of the code, and more specifically how to tokenize and shift the letters using Caeser shift. The problem im coming across is that it is not showing anything past the users input. After running it, it just stays there running without showing anything.
Cipher:
package cipher;
import java.util.Scanner;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
public abstract class Cipher {
public String message;
StringBuilder encrypted_message, decrypted_message;
[Code] ....
The constants have their own separate class, and they appear to work fine. I know that the Transpose and Reverser are incomplete, hence them commented out. But if i cant finish with Caeser first, it wont work at all.
View Replies
View Related
Apr 15, 2014
So I have this file in which has a few sentences on a single line. What I need to be able to do is read the file and then take each word and create a token out of it. Then what it does is it selects the first letter of every 5th word, uppercase it, and then allow me to use append it via a stringbuffer object to create a word out of it.
I know I'll need to use a string tokenizer but I'm not sure how to do so in a way that makes each word separate and how to tell it to only hit the 1st letter of every 5th word.
Here's what I've come up with so far, but I'm currently at a loss at what to do and my textbook/documentation is just not working.
Java Code:
String line; // The line we read from the file.
char letter; // The first letter of each 5th word.
String sw; // The completed string.
public static void main (String [] args)throws IOException {
[Code] ....
View Replies
View Related
Nov 7, 2014
So it is the question: This program implements a simple "decoder ring". It will prompt the user for a message to decode and decode the message based on the following substitution rules:
ABCDEFGHIJKLMNOPQRSTUVWXYZ will map to
ZEBRASCDFGHIJKLMNOPQTUVWXY
abcdefghijklmnopqrstuvwxyz will also map to
ZEBRASCDFGHIJKLMNOPQTUVWXY
any other characters (like space, punctuation, will map to themselves)
so if it sees an 'A' (or an 'a'), it will map to 'Z', etc... All i could think of is this but can't figure out the rest.
import java.util.Scanner;
public class DecoderRing
{
public static void main(String[] args)
{
String1[] = 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z';
String2[] = 'Z','E','B','R','A','S','C','D','F','G','H','I','J','K','L','M','N','O','P','Q','T','U','V','W','X','Y';
}
}
Not sure, what things are necessary such as switch statements or if and else or for loops and such...
View Replies
View Related
Sep 28, 2014
The problem is the result of encoded message can't not restore to the original message by the decoder. Here are my three class's code
SecureMsgMain:
package securemsg.core;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import securemsg.database.*;
public class SecureMsgMain {
[Code] .....
View Replies
View Related
Apr 21, 2015
Im trying to HTML/JavaScript ecode the getmessage calls in the code listed below. The code below is a snippit from a program which is used to handle a failed authentication attempt.
if(logger.isDebugEnabled())
logger.debug("Authentication Failure: " + exception.getMessage());
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authentication Failed: " + exception.getMessage());
View Replies
View Related
Oct 30, 2014
I have a driver and a main program. How would I go along with calling the encode method to the driver class that I made so I can have the user inputs affected by the encode method?
Java Code:
public class ShiftEncoderDecoder
{
private int shift;
public ShiftEncoderDecoder(int shift)
{
setShift(shift);
}
public int getShift()
[Code] ....
View Replies
View Related
Apr 12, 2014
We have been tasked to create a Vigenere Cipher. At this stage however, I am attempting to get the program to encrypt a phrase using a single letter key (Caesar cipher), before progressing to the final stage, implementing a functioning Vigenere Cipher. The code below is able to encrypt a word, capatalise it, remove white space and shift it a certain amount of places, given the provided letter. My problem is that because the single letter is a String, not a char, the phrase is being shifted incorrectly. For example, when the program is given the Inputs: This is a test with the single letter key A, the program shifts all the characters by 1. The output however should read THISISATEST as A is supposed to be 0.
import java.util.Scanner;
public class VigenereCipher {
public static void main(String[] args)
{
char c;
[code]....
View Replies
View Related
Jul 29, 2014
I am trying to encrypt a string using substitution cipher, the program doesnt show any errors but the output is not what is expected. On encryption it shows random characters whereas i want it to be encrypted by another letter. This is what I have done:
/* Encryption using substitution */
import java.io.*;
public class SSExp1 {
public static void main(String args[]) {
char[] ip= new char[20];
char[] op= new char[20];
char key = '3';
String b;
[Code] .....
View Replies
View Related
May 8, 2015
I have an program with an encryption and a decryption method, it works fine when i specify a name for the encrypted file, but i want the name for the encrypted file to be in cipher text, how do i do this and specify the path? i have marked out the "encryptionPath" specifically for specifying the location of the encrypted file which will have a cipher text name.
Here is my code so far
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
[Code] ......
View Replies
View Related
Feb 8, 2015
I was tasked with creating a program that encrypts a line of text (for example, CANDY) by shifting the letters X amount of times. For example, if the user inputs the sentence CANDY and selects a shift of 5, the output would be: HFSID. I got this part working fine. The issue I am having is with the decryption part of the program.
This is simply the reverse of the above, as the user would enter the phrase HFSID, with a shift of 5, and the program would output: CANDY. It works fine, all except for one letter, being the "F" letter. With my code, when I enter the above word to be decrypted it outputs: C[NDY
Obviously, that [ bracket is not an 'A'. I realise the issue falls with the equation, Here is my code:
public class SimpleEncryption {
/**
* @param args the command line arguments
*/
static int answer;
public static void main(String[] args) {
String cipher = JOptionPane.showInputDialog(null, "Please enter a sentence or word that you wish to encode or decode. This program uses"
+ " a basic cipher shift.");
[code]....
View Replies
View Related
Oct 1, 2014
I have following Cipher Code and test for it. But I am getting following exception.
Java Code:
java.lang.IllegalStateException: Cipher not initialized
at javax.crypto.Cipher.checkCipherState(Cipher.java:1672)
at javax.crypto.Cipher.doFinal(Cipher.java:2079)
at com.anjib.util.CipherUtil.encrypt(CipherUtil.java:67)
at com.anjib.util.CipherTest.testEncryptDecrypt(CipherTest.java:23) mh_sh_highlight_all('java'); Java Code: public class CipherUtil {
private static Logger log = Logger.getLogger(CipherUtil.class);
[Code] ....
View Replies
View Related
Jun 30, 2014
I want to encrypt a file and decrypt it on another host. For decryption on another host I guess I need to transfer the cipher... how can this be done? How can you write a Cipher to disk?Or am I completely on a wron track?
The following code is doing it already on one host:
package test;
import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import java.security.Provider;
import javax.crypto.*;import javax.crypto.spec.DESKeySpec;
[Code] ....
View Replies
View Related
Mar 30, 2015
I've a problem in encoding a URL string.
I know to encode a string we use,
URLEncoder.encode(stringname,"UTF-8");
But when I use this I'm getting an error telling that the encode method will accept only 1 String argument.
View Replies
View Related
Mar 14, 2014
import java.awt.*;
import javax.swing.*;
public class InstantMessageFrame extends JFrame
{
private JList friends;
private JTextField message;
private JButton send;
[code]...
1. Open the source code file of your InstantMessageFrame class from Lab 12.2.
2. Add the following three fields to the InstantMessageFrame class: a JTextField named message, a JList named friends, and a JButton named send.
3. Add a method to your InstantMessageFrame class named getMessagePanel()that returns a JPanel and has no parameters. (This method will create a JPanel that will appear in the south border of your JFrame. It will contain a text field in which a message can be entered and a button that sends an instant message to all the friends in the list.)
4. Within getMessagePanel(), instantiate a new JPanel and give it BorderLayout.Assign a message equal to a new JTextField by using the no-argument constructor of JTextField. Assign send to a new JButton,passing in "Send" to the constructor. (This will be the label on the button.)
5. Within getMessagePanel(), add the message text field to the center of the JPanel and add the send button to the east border of the JPanel. The panel is now ready, so return the JPanel reference.
6. Add a method to your InstantMessageFrame class named get-FriendsPane() that returns a JScrollPane and has no parameters.(This method will create a scrollable list that will contain the names of others that you can chat with.)
7. Within getFriendsPane(), assign friends to a new JList by using theno-argument constructor of JList.
8. Within getFriendsPane(), instantiate a new JScrollPane using the following statement: JScrollPane pane = new JScrollPane(friends);
9. The scroll pane is ready, so return the reference pane at the end of getFriendsPane().
10. Within the constructor of InstantMessageFrame, invoke getMessagePanel(),placing the returned panel in the south border of the content pane of InstantMessageFrame.An Introduction to GUI Programming 399
11. Within the constructor of InstantMessageFrame, invoke get-FriendsPane(), placing the returned scroll pane in the center of the content pane of InstantMessageFrame.
12. Save, compile, and run the InstantMessageFrame class.Your InstantMessageFrame now has three visible components: a JList,a JTextField, and a JButton.
View Replies
View Related
Mar 11, 2014
I'm very new to java code I'm currently learning about loops I've tried to write this for a statement in the program I'm making but its not working. I keep getting this message
LoanQualifier.java:26: error: illegal start of expression
if (salary >0||<=250000)
^
LoanQualifier.java:28: error: illegal start of type
if (yearsOnJob >0||<50)
I'm using Jgrasp for a complier
View Replies
View Related
Apr 4, 2015
if i send messages as in the code below, is there a way to read only one message, if the client doesn't know how long it is (or if he only knows the maximum length)?in the documentation it says, that the method read(byte[]) reads until no data ist available or end of file is decteted. What does the latter mean? Can i extend the array that i sent by a byte that signals the end? Here is my Code:
Server
public class Server implements Runnable{
ServerSocket server;
HashMap<Short,Socket> clients;
public Server(){
clients = new HashMap<>();
[code]....
Both are startet in seperate threads. At the moment the first output of the client is "12 bytes read", and then continously "-1 bytes read"(because the server closes).
View Replies
View Related
Apr 22, 2014
I am new to the JMS technology. I have written one sample sender and receiver program to pass a string message to the JMS queue and retrieve it back. It is working fine as well. But now, I want to pass a xml file to the JMS queue. Then from there I need to read the XML file and convert it into a Java object Using Jaxb. I know how to convert an XML into java object using Jaxb. But i am unable to send the XML file as a jms message to the listener.
View Replies
View Related
Jan 22, 2015
I want to send a message to a specific client in a server. This is my code and what I tried(I have only given you 3 classes in which I believe I have the problem).
TextClient:
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class TextClient {
public TextClient() {
[Code]...
View Replies
View Related
Sep 17, 2014
Im debugging a code that has the following setting:
<application>
<message-bundle>com.web.resources</message-bundle>
<locale-config>
<default-locale>en_US</default-locale>
<supported-locale>fr_FR</supported-locale>
</locale-config>
<resource-bundle>
<base-name>com.web.resources.message</base-name>
<var>message</var>
</resource-bundle>
</application>
Just want to ask, for example I have message_en_US.properties and message_en_SG.properties.And the web is currently using the SG property but one property is not exist on it, can I just redirect to use the US property?
View Replies
View Related
Oct 16, 2014
I wrote stand alone program to post message to IBM MQ , not sure if it posted to queue i see these Another 2,102 character(s) omitted is that mean it didnt post complete message? do i have to increase capacity of text size
JMS Message class: jms_text
JMSType: null
JMSDeliveryMode: 2
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d512042454c4b2e4d49462e514d47ad662c5420128a02
JMSTimestamp: 1413500135480
[Code]...
View Replies
View Related
Nov 11, 2014
String path = "/AUTOSAR/Os_0?type=EcucModuleConfigurationValues";
String path1[] = path.split("?type");
I want to split string in such a way that I should get the content before "?" in an another variable. I tried various way but some how I am not getting expected behavior.
View Replies
View Related