i had a ton of fun with this challenge. took me 2 days!
i wrote a little java program to help me out, but for the sake of fun, i've left out an important variable you'll have to find on your own. it takes input, either in the form of a number or a password, and returns the comparison. good luck! pm me if you need any help.
- Code: Select all
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
public class extbasic11 {
static int[] primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101};
static char[] chars = {'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'};
private static Scanner s;
private static final long MAGIC_NUMBER = /*i'll never tell!*/;
public static void main(String[] a) {
s = new Scanner(System.in);
System.out.print("attempt: ");
String in = s.next();
System.out.print("\n");
if(in.matches("[a-z]*")) {
int val = 1;
for(char check : in.toCharArray())
val *= primes[Arrays.binarySearch(chars, check)];
System.out.print("return: " + val + "\n");
int diff = 32 - ("" + Integer.toBinaryString(val)).length();
System.out.print("result: ");
for(int i = 0; i < diff; i++)
System.out.print("0");
System.out.print(Integer.toBinaryString(val) + "\n");
System.out.println("target: 00" + Integer.toBinaryString((int)MAGIC_NUMBER) + "\n");
main(null);
} else if(in.matches("[0-9]*")) {
if(in.length() > 18) {
System.out.println("too long!\n");
main(null);
}
int val = (int)Long.parseLong(in);
boolean primecheck = true;
for(int pcheck : getPrimeFactors(Long.parseLong(in)))
if(pcheck > 101)
primecheck = false;
if(primecheck) {
System.out.print("return: ");
for(int pcheck : getPrimeFactors(Long.parseLong(in)))
System.out.print(chars[Arrays.binarySearch(primes, pcheck)]);
System.out.print("\n");
} else
System.out.println("return: cannot translate to password");
int diff = 32 - ("" + Integer.toBinaryString(val)).length();
System.out.print("result: ");
for(int i = 0; i < diff; i++)
System.out.print("0");
System.out.print(Integer.toBinaryString(val) + "\n");
System.out.println("target: 00" + Integer.toBinaryString((int)MAGIC_NUMBER) + "\n");
main(null);
} else
System.exit(0);
}
public static ArrayList<Integer> getPrimeFactors(long n) {
ArrayList<Integer> ret = new ArrayList<Integer>();
if(n==1)
ret.add(102);
while(n%2 == 0) {
ret.add(2);
n = n/2;
}
for(int i = 3; i <= Math.sqrt(n); i = i+2) {
while(n%i == 0) {
ret.add(i);
n = n/i;
}
}
if(n>2)
ret.add((int)n);
return ret;
}
}