Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class EncryptingPassword {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int input = Integer.parseInt(scanner.nextLine());
- String encryptedPassword = "([\\W+\\w\\d]+)>(?<firstGroup>[0-9]{3})\\|(?<secondGroup>[a-z]{3})\\|(?<thirdGroup>[A-Z]{3})\\|(?<forthGroup>[^<>]{3})<\\1";
- Pattern pattern = Pattern.compile(encryptedPassword);
- Matcher matcher = null;
- for (int i = 0; i < input; i++) {
- String inputText = scanner.nextLine();
- matcher = pattern.matcher(inputText);
- if (matcher.find()){
- StringBuilder password = new StringBuilder();
- String first = matcher.group("firstGroup");
- String second = matcher.group("secondGroup");
- String third = matcher.group("thirdGroup");
- String forth = matcher.group("forthGroup");
- if (!first.equals("0") && !second.equals("0")&&!third.equals("0")&&!forth.equals("0")) {
- password.append(first).append(second).append(third).append(forth);
- System.out.printf("Password: %s%n", password);
- }else {
- System.out.println("Try another password!");
- }
- }else {
- System.out.println("Try another password!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment