Creating Encryption / Decryption Program?

Feb 25, 2015

For this week's assignment, I am supposed to create a java program that encrypt's a user's sentence, outputs the encrypted message, then decrypts the message, outputting the user's original message.

This is what I have so far. It doesn't compile the last few lines since that is not correct Java syntax.

Java Code:

import java.util.Scanner;
import java.io.*;
public class Decrypter {
public static void main(String[] args) {
String sentence;
final char REAL_ALPHA[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',

[Code] .....

So you can see I have "realAlpha" which are regular letters of the alphabet, and "codeAlpha" which are the letters I want to encrypt with. I want 'a' equal to 'z,' 'b' equal to 'y', 'c' equal to 'x' and so forth in that sort of reverse order, you know? So the word "apple" would encrypt into "zkkov."

I am stuck as to how to replace the letters in this way. You can see I tried fumbling with sentence.replace to switch the letters out between the two arrays. Also, I only barely understand arrays.

View Replies


ADVERTISEMENT

Simple Encryption / Decryption Program

Nov 1, 2014

I have to write an encryption/decryption program for a sentence entered by the user that uses arrays. Here is my code so far. I'm kind of lost on what to do next in the code.

import java.util.Scanner;

/*Program that encrypts then decrypts a sentence
Encryption
*/
public class Encryption extends java.swing.JFrame{

[code]....

View Replies View Related

Encryption - Decryption Alphabet

Mar 8, 2014

I want to create a java program that can be encrypt-decrypt alphabet from characters . Which is the shifting of the alphabet is starting from the the first character to increase 4 and 5 increased in the second character, increasing 6 at the third character, and so on..

Then when one of the characters increasement is more than the ascii code of 'z', that character will decrease from the variable i from the loop. This is the output of the program that i want:

Encryption:
Plain text: "abcz"
Cipher text: "egiz"

Decryption:
Cipher text: "egiz"
Plain text: "abcz"

This is my code for now:
 
package -;
 public class - {
 public static void main(String[] args) {
  String enkripsi = "abcz".toLowerCase();
String dekripsi = "egiz".toLowerCase();

[Code] ....

What's wrong with my code? It won't work. Specially in the decryption.

View Replies View Related

How To Use RSA For Encryption / Decryption Of Large Files

Mar 14, 2015

I need to encrypt/decrypt file contents using RSA . But the default nature of RSA I could not upload files larger than 177 bytes for key length 1024 bytes . How it can avoid , I look it for a 100 times yet...

I attach my encryption files here ...

See attached files for more details ...

View Replies View Related

RSA Encryption Decryption Using Separate Codes With GUI

Aug 16, 2014

I am creating 2 different java codes for encryption and decryption separately based on RSA algorithm. The codes also involve swings for GUI. The problem with these codes are that my string is getting encrypted but after decrypting it,i do not get the string rather i get string of random numbers and alphabets. I am posting both the codes.

Encryption code:

import java.math.BigInteger;
import java.util.Random;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class cipher implements ActionListener

[Code] ....

Now the decryption code

import java.math.BigInteger;
import java.util.Random;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class decipher implements ActionListener

[Code] ....

The screenshots for respective codes are as attachments ....

View Replies View Related

Running Encryption / Decryption Application - Could Not Find Main Class

Jun 23, 2014

I am trying to put together an encryption/decryption application that will essentially accept a sentence that is submitted, and spit out the encrypted version and then switch it back to the correct sentence. I have been told to nest my information in the class (rather than the main), but am having difficulty actually understanding how to do this. The error that Eclipse is throwing me is also that it "could not find the main class." Here is my code:

import java.util.Arrays;
import java.util.Random;
public class encryptingWords {
public static void main(String[] args) {
final int ALPHASIZE = 26;
final char[] Lalpha =

[Code] .....

View Replies View Related

Encryption / Decryption - How To Separate Digits To Make Numbers Encrypted

Nov 4, 2014

I've written most of the code (along with another classmate) to get this to work, but I can't seem to return the encrypted value. I'm also trying to figure out how to separate the digits (or if I'm supposed to) to make the numbers encrypted. The main kicker is that we have to be using methods to return the final values. Everything compiles, (It compiles, but no results really.)

A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that will encrypt their data so that it may be transmitted more securely. Your program should read a four-digit integer number and encrypt it as follows: Replace each digit by the remainder after (the sum of that digit plus 7) is divided by 10. Then, swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Do the encryption in a method and send the encrypted number back to main.

Here are the method headers: public static int encrypt(int num) // Takes num as a parameter and returns the encrypted value public static int getnum() // gets one number from the user Example: If the user enters 1234 they should see: 0189

import java.util.Scanner; //Needed for Scanner class
public class LNFI_LNFI_program2
{
public static void main(String[] args)
{
getnum(); //Calls for getnum() method

[Code] ....

View Replies View Related

Creating A Program That Will Compile And Run Another Java Program

Feb 20, 2014

I'm creating a program that will compile and run another java program:Lets say I have a program in directory

D:HelloWorldsrc
and compiled program will be in
D:HelloWorldin
inside src and bin is a folder hello (that's a package)

package hello;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
System.out.println("Hello World");
}
}

This program will be run by another program (that's the program that I am creating).Here is the code of my program:

package runnercompiler;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
public final class RunnerCompiler {
 
[code]....

View Replies View Related

Exception In PGP Decryption

Oct 16, 2014

I want to encrypt and decrypt a txt file by using PGP.I completed my PGP Encryption.I'm getting an error in PGP Decryption. The error msg as follows

Quote:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid PGP message
at com.newpackage.bouncy.PGPUtils.getDataList(PGPUtil s.java:502)
at com.newpackage.bouncy.PGPUtils.decryptFile(PGPUtil s.java:198)
at com.newpackage.bouncy.PGPFileProcessor.decrypt(PGP FileProcessor.java:56)
at com.newpackage.bouncy.Tester.testDecrypt(Tester.ja va:46)
at com.newpackage.bouncy.Tester.main(Tester.java:61)

I am getting this error in the following line of my code.

PGPObjectFactory factory=new PGPObjectFactory(PGPUtil.getDecoderStream(is));
=>> Object obj=factory.nextObject();//here i am getting obj as null
if (obj == null) {
//System.out.println("Invalid PGP Message");
//System.exit(0);

[Code] .....

View Replies View Related

Decryption - Data Must Not Be Longer Than 128 Bytes

Oct 21, 2014

Button Code:

private void DecryptBActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
final String plainText;
if (!areKeysPresent()) {
// Method generates a pair of keys using the RSA algorithm and stores it
// in their respective files
generateKey();

[Code] ....

Everytime throwing exception "javax.crypto.IllegalBlockSizeException: Data must not be longer than 128 bytes" in decrypt method.

View Replies View Related

Access Restriction Error In Decryption Code

May 21, 2015

I am getting error message on Java code that was developed by someone else and is supposed to work.

public String decrypt(String password) {
try {
// create the key and parameter spec
KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, interactions);
SecretKey key = SecretKeyFactory.getInstance(keyFormat).generateSecret(keySpec);
AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, interactions);
// create the cipher

[code]...

the error message is as follows: Access restriction: The type 'BASE64Decoder" is not API (restriction on required library '/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/lib/rd.jar')I am using eclipse.

View Replies View Related

Finishing / Creating Checkerboard Program

Sep 9, 2014

I have my CheckerboardViewer done, my component is what I need finishing. My final product needs to be a checkerboard with alternating red and grey squares but the background is already grey. My code for the Viewer is:

import javax.swing.JFrame;
public class CheckerBoardViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(300, 400);
frame.setTitle("CheckerBoardViewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CheckerBoardComponent component = new CheckerBoardComponent();
frame.add(component);
frame.setVisible(true);
}
}

And this is what I have of the Component:

import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

[code]....

I've created one square so far, but I'm having trouble creating the code for at least the second square.

View Replies View Related

Creating A Program To Call Classes

Aug 15, 2014

The requirements are as follows:Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:

A. Set the day.

B. Print the day.

C. Return the day.

D. Return the next day.

E. Return the previous day.

F. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add four days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.

G. Add the appropriate constructors.

H. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G.

I. Write a program to test various operations on the class Day.Should I break down my day.java into several separate classes, one for each of the sections (previous, next, etc)?

import java.util.*;
public class MyDay
{
static Scanner readinput = new Scanner(System.in);
String day;
public MyDay(String day)
{
day = "Sunday";

[code]....

Ideally I would like to create a Gui that would have someone type in the day, and then press a button to return the next day, prior day, or have a text input to test for adding X number of days.

View Replies View Related

Creating Number To Word Program?

Apr 1, 2015

I was given the assignment of creating a number to word program for my first college java programming homework.

Here is what I have created so far :

import java.util.*;
public class PrintNumberInWord { // saved as "PrintNumberInWord.java"
public static void main(String[] args) {
int number = 5;
Scanner sc = new Scanner (System.in); {
System.out.println ("Enter a number");
System.out.println(" ");
if (number == 1) {

[Code] .....

The first lines were made for us so we could follow a guideline, however, no matter what I type the command prompt displays 5 to me, I know thats because 5 is defined in the beginning but backspacing 5 causes the program not to work at all, how can I get this program to work properly?

View Replies View Related

Java AES File Encryption

May 10, 2015

I have a program that encrypts and decrypts using the AES algorithm, but I have to specify the name of the encrypted file, and also specify the format of the original file as part of the name of the encrypted file. I will like to know how how to implement the following features into my code : 1.)I want the name of the encrypted file to be in cipherText 2.) i want the computer to be able to decide the file type(extension eg.txt) without me having to specify it, for example in my code if I am encrypting a .jpg file, I have to specify the name of the encrypted file as encrypt.jpg

Here is my code which i have tried to implement:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;

[Code] ....

To see if I could get the file name to be in cipher text but I got these errors:

Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at EncryptDecrypt.encrypt(EncryptDecrypt.java:48)
at EncryptDecrypt.main(EncryptDecrypt.java:37)

View Replies View Related

Creating Program For Area And Perimeter Of Triangle

Sep 1, 2014

import java.lang.Math;
public class triangle {
double area; double s;
public double findArea(double sideA, double sideB, double sideC);
{
s= 0.5 *(sideA + sideB + sideC);
area = Math.sqrt(s*(s-sideA)*(s-sideB)*(s-sideC));

[Code] ...

Errors I am getting:

Triangle.java:23: error: class, interface, or enum expected
import java.util.Scanner
^
Triangle.java:25: error: class, interface, or enum expected
public static void main(String[] args) {

[Code] ....

View Replies View Related

Creating A Text File With Program Output

Sep 21, 2014

I'm trying to copy my program output to a text file and still have it be displayed in the console.

View Replies View Related

Creating Program With Constructors And Calculate Result

Feb 11, 2015

The end result is when I print the total it comes out to be 0. Trying to solve this

package pay;
import java.util.*;
public class manager
{
public manager(String string, int i, String type) {

[Code] ......

View Replies View Related

Creating Program That Will Handle A Golfer And His Scores

Apr 22, 2015

I have a project that is asking me to create a program that will handle a Golfer and his scores. The program will be comprised of three classes: a Golfer class that will manage all the golfer's scores, a Score class and a Tester class to drive the other classes. To accomplish this task the program will use a partially filled array to store the golfer's scores. I have the majority of the code written. It compiles fine, but when I compile and run it only gives the following output.

Tiger ID Number: 1001 Home Course: Pebble Beach
Score Date Course Course Rating Course Slope
[LScore;@15db9742

I am not sure what I am doing wrong. I have been over and over the code. It is also only printing one golfers information. I have tried creating a for loop for the for the toString in the Golfer class but I am getting the following error Golfer.java:117: error: missing return statement.

I am at a loss here is the code I have for the three sections.

public class Golfer
{
private String name;
private String homeCourse;
private int idNum;
private Score[] scores;
private static int nextIDNum = 1000;

[Code] ....

View Replies View Related

Creating Palindrome Program - Arrays And For Statements?

Feb 14, 2015

I am trying to create a program that reads a sentence, such as: "abba is running to the radar" scans this sentence, and then prints out all the palindromes. I am running into issues with my arrays and for statements. Here is my code:

static String palindrome, backwardsLower,
palindromeLower, palindromeClean, backwards2, backwards = "";
static String[] words;
static int counter;
public static void main(String[] args) {
palindrome = JOptionPane.showInputDialog("Please enter a phrase. " +

[Code] ...

I am aware that there is a few "useless" variables in there at the moment, I will clean them up (as well as some useless statements, I see those too). The issue comes at about line 17. The variable backwards REMOVES all the spaces from the array, so when it comes time to compare the strings, it is comparing individual words to the ENTIRE string, thus no words will ever be a palindrome.

View Replies View Related

Creating A Program That Calculates Simple And Compound Interest

Aug 12, 2014

I need getting started designing and creating a program that calculates simple and compound interest. Simple interest in this case means that interest is only applied to the original amount. For instance, if a person deposits $1000 at 10% annual interest, then after one year they would have $1100 (the original $1000 plus the $100 interest) and after two years they would have $1200 (the original $1000, plus the $100 earned the first year, plus the $100 earned the second year).

With compound interest, the interest is applied to all money earned. So, starting with $1000 at 10% annual interest, after one year the user would have $1100 (the original amount plus $100 interest) and after two years the user would have $1210 (the $1100 they started with at the beginning of the year plus the $110 interest).

The requirements of this program are:

-Create a class that will hold methods to calculate the interest. Do not include the main method in this class.
-In the class that is used to calculate the interest, include a method to print to the screen, by interest period, the starting amount for the period, the interest earned for the period, and the total amount at the end of the period. Note that each period represents the time frame for how often it is updated. If annual is selected the period is every year. If it is semi-annual it is every six months. If it is quarterly it is every three months.
-Create a demo class that will use your interest calculation class. Prompt the user for the original amount, the type of interest (simple or compound), the annual interest rate, and whether it is updated annually, semi-annually, or quarterly. Use method calls to your calculate interest class to do all calculations and display the result. Loop the program until the user chooses to quit.

Sample output ($10000 initial investment, 10% simple interest, annual, for 4 years):

Period Beginning Amount Interest Earned Ending Amount
1 10000.00 1000.00 11000.00
2 11000.00 1000.00 12000.00
3 12000.00 1000.00 13000.00
4 13000.00 1000.00 14000.00

View Replies View Related

Creating TXT File - Program Keeps Printing Exception Error

Apr 10, 2014

I'm trying to have the program create a .txt file for me but it is not working properly. It just keeps printing the exception error "The file could not be found" and exits the program.

// This program asks the user for input for a name, phone number and notes up to 200 entries.
// It stores every contact in a file. Type 'h' for help while running this program.

import java.util.Scanner;
import java.io.*;
public class Phonebook {
static Entry[] entryList = new Entry[200];
static int numEntries;
public static void main(String[] args) {

[Code] ....

After running the code, I go into my workspace folder and I see that the file was created. What to do because running the program will always print "could not find the file".

View Replies View Related

Creating Java Program That Prints The Smallest Number

May 9, 2015

Here is my code :

import java.util.Scanner; 
public class smallestnumber
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in); 
int smallest =0;
int number;

[Code]...

here is the output of my code:

Enter the number
88
Enter the number
8
Enter the number
6
Enter the number
55

[Code]...

Why is it printing 0 instead of 1?

View Replies View Related

Program Like Applet - Creating Multithreading Or Drawing Objects

Aug 20, 2014

What is the best choice to program like an applet i mean easy with creating multithreading or drawing objects etc.

View Replies View Related

RSA Encryption Using Fast Exponential Technique - Big Integer

Apr 17, 2012

I'm currently working on a RSA Encryption using Fast Exponential technique. As the numbers I'm working with will be very huge, I am forced to use BigInteger.

As this is the first time I'm using Big Integer, I encountered quite a number of issues. I'll try my best to explain the errors I'm facing:

1. I had done this step: BigInteger d;

So I'm currently trying to get d = 0;

However, I keep getting an error required: BigInteger, found int.

When I changed it to d = new BigInteger(0) , I get this error:

java:19: error: constructor BigInteger in class BigInteger cannot be applied to given types;

d = new BigInteger(0);
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length

Part of Code:

public class BigFastExponential
{
BigInteger e; // public exponenet: all has this
BigInteger d; // private key: only key owner has this
BigInteger n; // public modulus: all has this

/**
* Create a LongRSA object for a public key holder, with just e and n.
*/
public BigFastExponential(BigInteger public_e, BigInteger public_n)

[Code] ....

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







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