Encrypt / Decrypt User Sentence Using Array And Random Encryption
Oct 28, 2014
My assignment is to write a program that will encrypt and decrypt a sentence entered by a user but the encryption is to be random using an array. Can I convert my sentence(string) from char to int then create a random array to encrypt?
import java.util.Scanner;
import java.util.Random;
/*SentenceEncryptionProgram
*/
public class SentenceEncryption {
string sentence; //sentence entered by user
[Code] ....
View Replies
ADVERTISEMENT
Apr 10, 2014
I've been given an assignment for my Programming Fundamentals class that requires the user to enter a word/sentence to encrypt or decipher, as well as requiring the user to enter a key in which to encrpyt/decrypt the input by.
So a = no shift, b = a shift by 1 and so on.
But I'm completely lost as to what to do, and after searching for Vigenere Cipher topics, they look completely different to mine and (hardly) include prompts?This is my code:
/**
* @(#)VigenereCipher.java
*/
import java.util.Scanner;
public class VigenereCipher
{
public VigenereCipher()
[code]....
View Replies
View Related
Feb 12, 2014
I am using AES/CBC/PKCS5Padding algorithm to encrypt/decrypt, it works fine across machines, since i am not using a Facrtory to create the secret . I am using constant SecretKeySpec and iv for the ciphers. This of course heart the security , and doesn't prevent the "man of the middle" problem .
I saw that there are ways with key generation with MAC , and RSA symmetric encryption , but i am not sure how to implement it , and how to it depends on local certificates or files .
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 13, 2014
I have to encrypt the strings present in an array to the alphabet after 2 positions
Example:
my name is x
should give an output
oa pcog ku z
Although i have taken an input but unable to increment the char in the array...
View Replies
View Related
May 1, 2014
I am trying to write a simple program that checks if a user's input has a specific letter using the ".contains" method but its not doing what i wanted to do. here is my code below.
import java.util.Scanner;
public class secret
{
public static void main(String args[]) {
Scanner sc;
char hidden='a';
String guess;
[Code] ....
View Replies
View Related
May 21, 2014
Ok, so I have to make a program that tells the user to type a sentence and at the end of the sentence a "." must be put to end the program. If a "." period is not entered, it must re-prompt the user to enter a period. On top of all this, the program has to count the number of letters in the sentence. I cant seem to get the while loop working and I cant find anywhere how to make a counter count the number of letters.
import java.io.*;
class Sentence
//The purpose of this program is to
[Code]....
View Replies
View Related
Feb 19, 2014
The purpose of this program is to translate a user inputed sentence into morseCode. It seems like everything is right to me, but I'm simply not getting output! What am I doing wrong, or what should I add/change?
Here is the main class:
public class MorseCode
{
public static String myInput;
public static String[] myMorse;
public static String myUserInput;
public static char[] myAlph = {'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'};
public MorseCode()
[Code] ....
View Replies
View Related
Nov 9, 2014
Program is running fine. I can create usernames and everything but somehow I cannot quit or exit the program when I enter my sentinal value "QUIT". Here is my program question: Create an application that will create a username for a school computer system. Input a user’s first and last name. The username will be the first letter of the first name followed by the first 5 letters of his last name followed by a random 3 digit number. Continue to create and display usernames until a sentinel value is entered.
import java.text.*;
import java.util.Random;
import java.text.DecimalFormat;
public class username
[code]...
View Replies
View Related
Nov 8, 2014
So I need to generate 10 random integers in the range 1-20 but i have to store them in an array called numbers. Then I have to call a method called displayArray which displays the contents of the array and for the assignment i have to use a for loop to traverse the array. The method header for the displayArray method is:
public static void displayArray(int[] array)
This is what I have done
public class RandomIntegers {
static int numbers = 0;
public static void displayArray(int[] array) {
System.out.println(numbers + "Numbers Generated");
[Code] .....
View Replies
View Related
Sep 8, 2014
I am wanting this program to prompt the user to enter a maximum value and a minimum value and the program should in theory generate a random number for the output. Here is my logic:
int maxRange1;
int minRange1;
static int range;
static Random gen;
Then in my mail argument:
gen = new Random();
Scanner input = new Scanner(System.in);
System.out.print("Enter the maximum number: ");
int maxRange1 = input.nextInt();
[Code] ....
I am able to return both the user prompts and get the inputted answer to appear but I am not getting a response for the prompt "The random number is: ".
View Replies
View Related
Feb 12, 2015
I need to fix a program in which the user must get a three random numbers in a row. They have five chances. This is what i have so far:
public static void main(String[] args)throws IOException {
// TODO code application logic here
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int num1=(int)(Math.random()*(9-0));
int num2=(int)(Math.random()*(9-0));
int num3=(int)(Math.random()*(9-0));
[Code] ....
View Replies
View Related
Feb 16, 2015
filling out a Random array: An Array of Specific Length Filled with Random Numbers This time what I need to do is take the elements from this Random array and assign them to a new Byte array:
for(int i = 0; i < limit-10; i++) {
Random dice = new Random();
int randomIndex = dice.nextInt(array.length);
if (array[randomIndex] < 128) {
System.out.print(array[randomIndex] + " ");
} else if (array[randomIndex] >= 128) {
System.out.print(array[i] + " ");
}
}
byte[] noteValues = new byte[]
{ 64, 69, 72, 71, 64, 71, 74, 72, 76, 68, 76 }; //This is the byte array filled manually!
I've tried amending the manual input to fit in with the Random array, as follows:
byte[] noteValues = new byte[]
{ array[randomIndex] };
In this case, however, the Byte array can't interpret the int values. Also, if the Byte array is outside the 'for' loop, array[randomIndex] cannot be resolved.
View Replies
View Related
Jul 25, 2014
Currently my java program is reading emails along with attachments from the mailing server. It works fine as long as the email and the attachments are "not" encrypted.
The problem comes when the email and/or the attachment are encrypted.
I need to extend my application so that it should be able to handle encrypted emails and attachments as well.
I did some research and found out that for decrypting the contents i need the private key of the recipient email id and the digital signature of the sender?
If my above understanding is correct, some reference java examples / snippets where i get some insight into the java api used to perform this?
View Replies
View Related
Aug 27, 2014
I am developing a java code using netbeans for encryption decryption by RSA algorithm. Swings and file handling play a major role in these code. My encryption code is working nicely but the code for decryption is not since keys file is not being read. That is why variable mod and pri are getting null values and the following error stack is coming. I know where the problem is somewhere in void readkeys() function but cannot solve it.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.math.BigInteger.modPow(BigInteger.java:1579)
at rsakeydecryption1.RsaKeyDecryption.decryption(RsaKeyDecryption1.java:167)
at rsakeydecryption1.RsaKeyDecryption.read_output(RsaKeyDecryption1.java:294)
at rsakeydecryption1.RsaKeyDecryption.actionPerformed(RsaKeyDecryption1.java:330)
[Code] .....
My code for decryption is
package rsakeydecryption1;
import java.math.BigInteger;
import java.util.Random;
import java.io.*;
import javax.swing.*;
[Code] ....
View Replies
View Related
Apr 7, 2014
I have been assigned to write a program that has a user input random numbers then the program is to sort them in different ways. I have the coding for the different sorts but, I have an error saying that I am missing a return statement in the "Bubble" method. I am trying to return "arr[i]" in the "for loop" which gives me this error, and when I try to take the "return arr[i]" outside of the "for()" loop the error reads the it cannot locate variable "i".
import java.awt.* ;
import java.awt.event.*;
import javax.swing.*;
public class SwingSorts extends JFrame implements ActionListener
{
JRadioButton bubble;
JRadioButton selection;
[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
Mar 23, 2013
I have an encryption utility class. Can i use it some how to encrypt password before submitting form? I heard it can be done using applet.
View Replies
View Related
Feb 2, 2014
I have about 100,000 (N) random long variables in an array. I'd like to find if any two longs are equal; they're not expected to be. At this size, should I use the Hashtable or brute force it at a cost of N^2/2?
View Replies
View Related
Dec 8, 2014
What the fastest way to sort an array of random integers. My instructor told me to look into an algorithm that uses 2n, but that is all he gave me. I am unable to find anything of the sort (pun intended there) on google, in my text, in my other java books or on here. The only thing that I have come up with are things like mergesort with the exception that the indicies of the Array have to be even. The program that I'm writing takes user input for a minimum to maximum range, the amount of numbers to fill the array in that range, and verbose.
I've tried bubbleSort but it takes forever to sort under the conditions below. I have seen a sorting algorithm that uses n (log n) but didn't really understand how that one worked.
Using the 2n algorithm, I should be able to test the range from 1 - 1000 and have it populate an array of of 1,000,000 random integers. It should be able to complete in a matter of miliseconds.
View Replies
View Related
Nov 10, 2014
For a project we have to "shuffle" items in an array using random numbers. We are supposed to generate random numbers and use those numbers to exchange array elements. But I am not sure what that means, "exchange array elements". Does that mean you generate 2 random numbers within the length of the array, and then switch the items at those locations in the array?
View Replies
View Related
Nov 21, 2014
I am writing a program that creates an array with random numbers. Then the user can choose what number of the array he/she wants to check the occurance of. This works fine, but the numbers generated seems very weird, only 2 of the 10 possible numbers are generated. 0 and one of the other 9 numbers, the 0 is always 10100 and the other one is always 101.
import java.util.Random;
import java.util.Scanner;
public class OppgaveC {
public static void sjekk() {
int randomArray[]=new int[101];
int countArray[]=new int[10];
Random rand = new Random();
[Code] ....
it also says i have a memory leak on my scanner, ow can i close this?
View Replies
View Related
Jun 15, 2014
I am having a hard time trying to figure out how to print random numbers from a an array list. I tried google but nothing worked. I have to pick certain values from two lists and print them on the screen. I have included comments in the code to facilitate the explanation.
import java.util.Random;
public class Parachute {
public static void main(String[] args) {
Random randomNumbers=new Random();
int number;
int array []={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
char A[] = {'a', 'b', 'c','d','e','f','g','h', 'i','j','k','l','m','n','o','p','q'};
[Code]...
View Replies
View Related
Apr 1, 2014
Trying to generate random integers, based off user-input for amount of integers, and then sort them into an array. The problem is that the second method needs to be int[] but I cannot figure out what to make the return result. The instructions say it needs to be an int[] in the UML diagram, so I know it's not supposed to be void.
Java Code:
public void generateNewSecret() {
Random rand = new Random();{
for (int i=0; i<numDigitsSet; i++) {
secretNumber[i]= rand.nextInt(10);
System.out.println("" + secretNumber[i]);
[Code] .....
View Replies
View Related
Feb 15, 2015
I was inquiring about selecting random numbers from a Fibonacci array, the original post for which is here: Exiting a 'for' Loop Early. I have managed to achieve this with the following code:
System.out.println("Random numbers from the Fibonacci array");
for(int i = 0; i < limit; i++) //Limit is an 'int' of 15 & is set as the length of the Fib. array. I'm calling it for the Random array, too!!
{
Random dice = new Random();
int randomIndex = dice.nextInt(array.length); //The Fib. array was simply called 'array'!!
if (array[randomIndex] < 100)
{
System.out.print(array[randomIndex]+ " ");
}
}
When the code prints I get a random set of numbers which occur in the Fibonacci sequence preceding it. However, the actual length of this Random array also changes each time, and never more than the limit of 15 specified in the 'for' loop. What I want to try and do is print the Random array with a specific length each time. I've tried changing the conditional statement of the 'for' loop in different ways to set the Random array's length, but had no luck.
View Replies
View Related
Oct 26, 2014
Write a program that creates an array that can hold 9 double values that represent baseball batting averages for a starting baseball lineup. Use a for loop to populate array with random double values in the range of 0.00 to 0.500. Recall that "double" values are what Java calls "real" numbers. Use a second for loop to print the values in the array with one number per line. Finally, use a third for loop to traverse the array and find and print the maximum batting average in the array. Note: you will need to use String.format to control the precision of a double number when you print it- Here is my code so far:
public class P2F {
public static void main (String[] args) {
double [] player= new double [9];
//player[0]= Math.random();
for (int index=0; index < player.length; index++) {
[Code] ....
When I open the terminal window I get different variations of this [D@4545c5]. I would like to know all the things I am doing wrong.
View Replies
View Related