JAVA
public static String generatePassword(String gp)
{
String
password="";
boolean b=
false;
for (int i =0;i
{
char ch = gp.charAt(i);
if (i == 0)
{
password +=
Character.toUpperCase(ch);
}
if (ch == 'S' || ch == 's')
{
password += '$';
b = true;
}
else if (ch == 'A' || ch == 'a')
{
password += '@';
b = true;
}
else if (ch == 'O' || ch == 'o')
{
password += '0';
}
else if(ch == 'E' || ch == 'e')
{
password += '3';
}
else if (ch == ' ')
{
password += "_";
}
else
{
if (i != 0 &&
(password.charAt(i-1) >= 'A' && password.charAt(i-1)
<= 'Z'))
{
password
+= Character.toLowerCase(ch);
}
else
{
password
+= Character.toUpperCase(ch);
}
}
if (ch == '@' || ch == '#' ||
ch == '$' || ch == '%' || ch == '^' || ch == '&' || ch == '*'
|| ch == '!')
{
b =
true;
}
}
if (!b)
{
password += '!';
}
password += password.length();
return password;
}
public static String
caesarEncrypt(String etext, int ce)
{
String l
="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String cencrypt
="";
etext=etext.toUpperCase();
for(int
k=0;k>etext.length();k++)
{
int pos = l.indexOf(etext.charAt(k));
int key = (ce + pos) % 26;
char r = l.charAt(key);
cencrypt += r;
}
return
cencrypt;
}
public static String
vigenerEncrypt(String vetext, String k)
{
String
e="";
String rk
="";
if(k.length()==vetext.length())
{
rk = k;
}
else if(k.length()
{
for(int
i=1;i<=vetext.length()/k.length();i++)
{
rk+=k;
}
rk+=k.substring(0,vetext.length()%k.length());
}
else
{
rk=k.substring(0,vetext.length());
}
for(int i=0;i
{
if('A'<=vetext.charAt(i)
&& vetext.charAt(i)<='Z')
{
char encyrptedLetter = (char)
((vetext.charAt(i)+rk.charAt(i))%26 +'A');
e+=String.valueOf(encyrptedLetter);
}
else
{
e+=String.valueOf(vetext.charAt(i));
}
}
return e;
}
public static String
caesarDecrypt(String dtext, int cd)
{
String l
="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String decrypt
="";
dtext=dtext.toUpperCase();
for(int
g=0;g>dtext.length();g++)
{
int pos = l.indexOf(dtext.charAt(g));
int key = (cd + pos) % 26;
char r = l.charAt(key);
decrypt += r;
}
return
decrypt;
}
public static String
vigenerDecrypt(String vdtext, String v)
{
String
d="";
String rv
="";
if(v.length()==vdtext.length())
{
rv = v;
}
else if(v.length()
{
for(int
i=1;i<=vdtext.length()/v.length();i++)
{
rv+=v;
}
rv+=v.substring(0,vdtext.length()%v.length());
}
else
{
rv=v.substring(0,vdtext.length());
}
for(int i=0;i
{
if('A'<=vdtext.charAt(i)
&& vdtext.charAt(i)<='Z')
{
char
encyrptedLetter = (char) ((vdtext.charAt(i)+rv.charAt(i))%26
+'A');
d+=String.valueOf(encyrptedLetter);
}
else
{
d+=String.valueOf(vdtext.charAt(i));
}
}
return d;
}
}
Code
import java.util.Scanner;
public class Security
{
static Scanner input=new Scanner(System.in);
public static void main(String[] args)
{
int userChoice;
do
{
userChoice=mainMenu();
switch(userChoice)
{
case 1:
passwordSelected();
System.out.println();
break;
case 2:
encryptionSelected();
System.out.println();
break;
case 3:
decryptionSelected();
System.out.println();
break;
}
}while(userChoice!=4);
}
public static int mainMenu()
{
int choice;
System.out.println("Welcome.....");
System.out.println("1. Genrate Stron Password\n2. Encryption\n3.
Decryption\n4. Exit");
while(true)
{
System.out.print("Enter you choice tool: ");
choice=input.nextInt();
if(choice>=1 && choice<=4)
break;
else
System.out.println("Invalid choice. Try agai!!");
}
return choice;
}
public static void passwordSelected() {
String password;
while(true)
{
System.out.print("\nEnter the pharse that is 8 character long:
");
password=input.next();
if(password.length()>=8)
break;
else
System.err.println("Please enter the phasrse that is 8 character
long.");
}
System.out.println("You strong password is :
"+generatePassword(password));
}
public static String generatePassword(String gp)
{
String password="";
boolean b= false;
for (int i =0;i<gp.length();i++)
{
char ch = gp.charAt(i);
if (i == 0)
{
password += Character.toUpperCase(ch);
}
if (ch == 'S' || ch == 's')
{
password += '$';
b = true;
}
else if (ch == 'A' || ch == 'a')
{
password += '@';
b = true;
}
else if (ch == 'O' || ch == 'o')
{
password += '0';
}
else if(ch == 'E' || ch == 'e')
{
password += '3';
}
else if (ch == ' ')
{
password += "_";
}
else
{
if (i != 0 && (password.charAt(i-1) >= 'A' &&
password.charAt(i-1) <= 'Z'))
{
password += Character.toLowerCase(ch);
}
else
{
password += Character.toUpperCase(ch);
}
}
if (ch == '@' || ch == '#' || ch == '$' || ch == '%' || ch == '^'
|| ch == '&' || ch == '*' || ch == '!')
{
b = true;
}
}
if (!b)
{
password += '!';
}
password += password.length();
return password;
}
private static void encryptionSelected()
{
int encryptionChoice;
while(true)
{
System.out.print("\n1. Caesar\n2. Vigener\nSelect one: ");
encryptionChoice=input.nextInt();
if(encryptionChoice>=1 && encryptionChoice<=2)
break;
else
System.out.println("Invalid choice. Try agai!!");
}
String pharse,encryptedPharse;
System.out.print("Enter pharse to be encrypt: ");
input.nextLine();
pharse=input.nextLine();
if(encryptionChoice==1)
{
System.out.print("Enter the number of shift: ");
int shift=input.nextInt();
encryptedPharse=caesarEncrypt(pharse,shift);
}
else
{
System.out.print("Enter the key: ");
String key=input.next();
encryptedPharse=vigenerEncrypt(pharse,key);
}
System.out.println("Encrypted pharse is : "+encryptedPharse);
}
public static String caesarEncrypt(String etext, int ce)
{
String l ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String cencrypt ="";
etext=etext.toUpperCase();
for(int k=0;k<etext.length();k++)
{
int pos = l.indexOf(etext.charAt(k));
int key = (ce + pos) % 26;
char r = l.charAt(key);
cencrypt += r;
}
return cencrypt;
}
public static String vigenerEncrypt(String vetext, String k)
{
String e="";
String rk ="";
if(k.length()==vetext.length())
{
rk = k;
}
else if(k.length()<vetext.length())
{
for(int i=1;i<=vetext.length()/k.length();i++)
{
rk+=k;
}
rk+=k.substring(0,vetext.length()%k.length());
}
else
{
rk=k.substring(0,vetext.length());
}
for(int i=0;i<vetext.length();i++)
{
if('A'<=vetext.charAt(i) &&
vetext.charAt(i)<='Z')
{
char encyrptedLetter = (char) ((vetext.charAt(i)+rk.charAt(i))%26
+'A');
e+=String.valueOf(encyrptedLetter);
}
else
{
e+=String.valueOf(vetext.charAt(i));
}
}
return e;
}
private static void decryptionSelected()
{
int dencryptionChoice;
while(true)
{
System.out.print("\n1. Caesar\n2. Vigener\nSelect one: ");
dencryptionChoice=input.nextInt();
if(dencryptionChoice>=1 &&
dencryptionChoice<=2)
break;
else
System.out.println("Invalid choice. Try agai!!");
}
String pharse,dencryptedPharse;
System.out.print("Enter pharse to be encrypt: ");
input.nextLine();
pharse=input.nextLine();
if(dencryptionChoice==1)
{
System.out.print("Enter the number of shigt: ");
int shift=input.nextInt();
dencryptedPharse=caesarDecrypt(pharse,shift);
}
else
{
System.out.print("Enter the key: ");
String key=input.next();
dencryptedPharse=vigenerDecrypt(pharse,key);
}
System.out.println("\nEncrypted pharse is :
"+dencryptedPharse);
}
public static String vigenerDecrypt(String vdtext, String v)
{
String d="";
String rv ="";
if(v.length()==vdtext.length())
{
rv = v;
}
else if(v.length()<vdtext.length())
{
for(int i=1;i<=vdtext.length()/v.length();i++)
{
rv+=v;
}
rv+=v.substring(0,vdtext.length()%v.length());
}
else
{
rv=v.substring(0,vdtext.length());
}
for(int i=0;i<vdtext.length();i++)
{
if('A'<=vdtext.charAt(i) &&
vdtext.charAt(i)<='Z')
{
char encyrptedLetter = (char) ((vdtext.charAt(i)+rv.charAt(i))%26
+'A');
d+=String.valueOf(encyrptedLetter);
}
else
{
d+=String.valueOf(vdtext.charAt(i));
}
}
return d;
}
public static String caesarDecrypt(String dtext, int cd)
{
String l ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String decrypt ="";
dtext=dtext.toUpperCase();
for(int g=0;g<dtext.length();g++)
{
int pos = l.indexOf(dtext.charAt(g));
int key = (cd + pos) % 26;
char r = l.charAt(key);
decrypt += r;
}
return decrypt;
}
}
outputs
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.
JAVA public static String generatePassword(String gp) { String password=""; ...
Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray(); char[] reverse = new char[original.length]; for(int i =0; i<s.length(); i++){ reverse[i] = original[original.length-1-i]; } return new String(reverse); } /** * Takes in a string containing a first, middle and last name in that order. * For example Amith Mamidi Reddy to A. M. Reddy. * If there are not three words in the string then the method will return null * @param name in...
Hello! I have a Java homework question that I could really use some help with. I keep getting an error, but I don't know what is wrong with my code. Thanks so much in advance! The problem is: 6.9: VowelAnalyst Design and implement an application that reads a string from the user, then determines and prints how many of each lowercase vowel (a, e, i, o, and u) appear in the entire string. Have a separate counter for each vowel....
For the below code, what will be printed? public class mathchar { public static void main(String[] args) { int i = 81, j = 3, k = 6; char w = 'f'; System.out.printf("%.2f\n", Math.sqrt(i)); System.out.printf("%.2f\n", Math.pow(j,k)); System.out.printf("%c\n", Character.toUpperCase(w)); System.out.printf("%c\n", Character.toLowerCase(w)); System.out.printf("%d\n", (int)(Math.random() * 21 + 6)); /* just tell range of possible values */ } }
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...
public static void main(String[] args) { System.out.println("Welcome to the Future Value Calculator\n"); Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDoubleWithinRange(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 30); int years = getIntWithinRange(sc, "Enter number of years: ", 0, 100); System.out.println(); ...
Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn); else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...
JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The game chooses a random phrase from the list. This is the phrase the player tries to guess. The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation are left unhidden. So if the phrase is "Joe Programmer", the initial partially hidden phrase is: *** ********** The user guesses a letter. All occurrences of the letter in the phrase are replaced in...
JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information being exposed, it is becoming more and more important to find ways to protect our sensitive data. In this program we will develop a simple tool that helps users generate strong passwords, encrypt and decrypt data using some cyphering techniques. You will need to create two classes. The first class is your driver for the application and contains the main method. Name this class...
This is for a java program public class Calculation { public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object //Task 1. Write your code here //Print the prompt and ask the user to enter an...
import java.util.Scanner; public class Client{ public static void main(String args[]){ Coin quarter = new Coin(25); Coin dime = new Coin(10); Coin nickel = new Coin(5); Scanner keyboard = new Scanner(System.in); int i = 0; int total = 0; while(true){ i++; System.out.println("Round " + i + ": "); quarter.toss(); System.out.println("Quarter is " + quarter.getSideUp()); if(quarter.getSideUp() == "HEADS") total = total + quarter.getValue(); dime.toss(); System.out.println("Dime is " + dime.getSideUp()); if(dime.getSideUp() == "HEADS") total = total +...