Make Simple Caesar Cipher That Takes In String As First Argument

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


ADVERTISEMENT

Make Simple Program Which Takes In Argument?

May 12, 2015

So I'm trying to make a simple program which takes in an argument (target) and then looks through an ArrayList of strings. If it finds a string that begins with (target) then it will return the index of that string. If it doesn't find a string which begins with (target) then it will return -1 instead.

For some reason, the program is always returning -1, rather than the index of the string within the ArrayList when there is one which matches the search criteria.

Here is the code:

public int getIndex(ArrayList<String> text, String target)
{
int i = 0;
int index = -1;
boolean found = false;

[Code].....

View Replies View Related

How To Change Number In Caesar Cipher

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

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 View Related

Simple Logic Error In Cipher-shifting Program?

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

Encrypt String Using Substitution Cipher

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

Encode URL String - It Will Accept Only 1 String Argument

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

Lexicographic Ordering - When Input String Values / No Output Takes Place

Jan 28, 2015

I have a assignment to do some Lexigraphic ordering. I have figured how to get the majority of this done, however, when I input my string values. No output takes place? :s

import java.util.Scanner;
public class Lab03c {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lexi = new Scanner (System.in);
String s1,s2;

[Code] ....

View Replies View Related

Why Main Method Has Argument String

Oct 6, 2014

One interviewer has asked me one question that why main() method has argument "String[] arg".What is reason behind this ??I am unable to explain it because i never think about it ..

View Replies View Related

Passing Object Argument To A Method - Unable To Call Methods On Argument

Feb 7, 2015

I am trying to pass an object of type Product p to my editProduct method, however trying to call p.getName(); doesn't work and throws a NullPointerException. The same kind of thing works for my displayRecord method (in a different class) and I can call .getName() on Product p, also passed as an argument to that method. Below is my editProduct class. The NullPointerExcepion is being thrown at line 61 (i.e., nameField.setText(p.getName());).

I don't know if I explained right, so here's a line thing of how the classes relate:

Search >>>(field.getText())>>> displayRecord(Product p) >>>editProduct(p)>>> EditProduct

And as a side note: adding the line p = new Product(); fixes it and successfully runs the class (including the Save and Quit parts) but obviously I want it to specifically refer to the Product I pass to the method.

Java Code:

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.ArrayList;
import javax.swing.BorderFactory;

[Code] ....

I'm asking a question because I don't understand how Product p could possibly be null, because the argument is passed through my DisplayRecord class, which also takes a Product p argument and works. In that class, I have declared Product prod = p; and prod is what I am passing to editProduct.

View Replies View Related

String Type Array As Argument Of Main

Sep 29, 2014

I have learn that every function in java is treated as a normal function including main() except that execution of a program starts here. I tried to overload it.

But I am getting error while doing so via String type array as an argument of main.

class Hello
{
public static void main()
{
System.out.println("Hello");
}
public static void main(String... s)
{
System.out.println("main from Hello");

[Code] .....

View Replies View Related

Make A Simple Calculator Program

Mar 11, 2015

i am working on my assignment in Compro 2, we are ask to make a simple calculator program

here's my code;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.BorderLayout;

[code]...

View Replies View Related

How To Make A Simple Connect Four Program Without GUI

Nov 19, 2014

My code below is trying to make a connect four program without GUI. I'm having trouble with getting the players to make their moves. What should I put in my "makeAMove" method...

Java Code:

public class Connect

final static int MAXROW = 6;
final static int MAXCOL = 7;
public static void main(String[] args){

[code]....

View Replies View Related

How To Make A Simple Password Strength Indicator

Jun 18, 2014

I am developing a number of Data Structures in Bluej. Iv created a nice little arraylist program, and want to add a password generator to this program. People are already prestored within the arraylist, and contain attributes such as ID, name, password, etc. I can search a persons name within the list and then view their ID, password, and encrypted password. I want to add a field which will show password strength, bare in mind the password is already stored within the program and will not be entered via the user.

I understand that this could be done via a regular expression, or using some count method where certain goals/sets of characters increase the count which determine strength.

View Replies View Related

How To Make Simple Java Application Installable

Sep 9, 2014

I want to create simple java application which has 3 text fields and the application will have database connection. Once done, I want to run this application on other systems without using any IDE. So how do I do this? How can I make an application installable on other system so that on clicking on it, it will start executing?

View Replies View Related

Make A Simple Platformer Game In Java - Moving Characters

May 24, 2015

I am trying to make a simple platformer game in Java. When I try to move the character I made it only moves over then immediately back

import java.awt.event.KeyEvent;
public class UCC
{
private int xLoc;
private int yLoc;
private int xSpeed;
private int ySpeed;
private double gravity;
private int size;
 
[code]....

View Replies View Related

Encoding A Message Using Caesar Shift

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

Find Common String Not Simple

Sep 17, 2014

i need to find common String between to Strings :

Example 1:
Customer Name 1: Dr. Joe Smith
Customer Name 2: Joseph Smith, MD.

I need to search the string for a match, in this example "Smith"

Example 2:
Customer Name1: New York Market Place
Customer Name 2: NY Marketplace

I need to search the string for a match, in this example Market place

Example 3:
Customer Name1: The Deli on the Corner
Customer Name 2: Corner Deli

I need to search the string for a match, in this example Deli Corner

View Replies View Related

Simple If Statement Taking A String Input Doesn't Work

Jun 6, 2014

Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
if (input == "next") {
System.out.print("good Job!");
}
else {
System.out.println("Why ?");
}

//If I type in next it prints out "Why ?" instead of "Good Job!" - Why though ?

View Replies View Related

Create Vigenere Cipher

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

Make A Switch With A String

Jan 9, 2015

I needed to make a switch with a string ,but eclipse told met there was an error and that the fix was to switch to 1.7 compliant. I did so and now when i run my program errors come back.

Here are the errors :

Exception in thread "main" java.lang.UnsupportedClassVersionerror: start : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)

[code]....

View Replies View Related

Specify Path Of Encrypted Filename In Cipher Text

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

How To Make A Method Splitting A String

Jan 14, 2014

How do I make a method that can seperate parts of a String. The String is [name,aid]... example [John,5],

I want to remove [ , and ] from the String... How can I do this?

This is what i've done this far:

static public String splitta(String tf)
{
String part1 = "";
String part2 = "";
String part11 = "";
String part22 = "";
String part111 = "";
String part222 = "";
String[] parts = new String[2];

[Code] ....

This dosn't work, it wont compile... It states the following:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at testprojekt.Validering.splitta(Validering.java:130)

View Replies View Related

Cipher Code - Encryption Test Cases Not Working

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

How To Transfer Cipher - Encrypt A File And Decrypt It On Another Host

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

Eclipse Takes Lot Of System Memory?

Jan 11, 2014

when running Eclipse, roughly 250k memory is used by it?In my Task Manager, it says: javaw.exe00265,000 KJava(TM) Platform SE binary.The value of 265,000 K is of course fluctuating, but around this value. Btw, this is when Eclipse is just running in the background, without even any java programs running in it. Is this normal memory usage by Eclipse?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved