Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Reverse Random Camel Case option #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Unusual options:

-rcc N {For passphrases - impose random camel-case; randomly uppercase the first N letters (default: 0)}

-rrcc N {For passphrases - impose random camel-case; randomly uppercase the last N letters (default: 0)}

At least one of the options -pw, -pp, or -k must be supplied. The keys, passwords, or passphrases produced by RandPassGenerator will be written to the standard output (stdout), so they can easily be redirected to a file. The -out option can also be used to write the output to a file. All messages are written to the standard error (stderr).

Detailed log messages are appended to the specified log file - if the log file cannot be opened, then the tool will not run.
Expand Down
2 changes: 2 additions & 0 deletions RandPassGenerator/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Unusual options:
-sep S For chunk formatting, use S as the separator (default: -)

-rcc N For passphrases, randomly upcase first N letters of each word (default: 0)

-rrcc n For passphrases, randomly upcase last N letters of each word (default: 0)

At least one of the options -pw, -pp, or -k must be supplied. The keys, passwords, or passphrases produced by RandPassGenerator will be written to the standard output (stdout), so they can easily be redirected to a file. The -out option can also be used to write the output to a file. All messages are written to the standard error (stderr).

Expand Down
37 changes: 37 additions & 0 deletions RandPassGenerator/src/gov/nsa/ia/gen/WordSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,43 @@ public String randomUpcase(String wrd, int n, AbstractDRBG drbg) {
return wb.toString();
}

/**
* Randomly upcase the last N letters of a provided word,
* drawing random from the given AbstractDRBG. If N is greater
* than or equal to the length of the input string, then all the
* letters are potentially subject to uppercase.
*
* @param wrd A string composed of letters
* @param n How many of the letters to possibly upcase at probability 1/2
* @param drbg random source
*
* @return a new string of same length with some letters possibly converted to uppercase
*/
public String reverseRandomUpcase(String wrd, int n, AbstractDRBG drbg) {
if (n <= 0) return wrd;

int len = wrd.length();
int y = len-n; // Measuring from the end of the word, go back n letters, start Random Upcase at letters equal to y
Integer ri;
StringBuilder wb = new StringBuilder(len);

for(int i = 0; i < len; i++) {
char c = wrd.charAt(i);
if (i >= y) {
ri = drbg.generateByte();
if (ri == null) {
logger.warning("WordSet - generateByte returned null, drbg problem, cannot upcase.");
return null;
}
if (ri.intValue() > 127) {
c = Character.toUpperCase(c);
}
}
wb.append(c);
}

return wb.toString();
}

// TESTING

Expand Down
28 changes: 26 additions & 2 deletions RandPassGenerator/src/gov/nsa/ia/pass/RandPassGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,10 @@ else if (!(Character.isLetterOrDigit(charsets.charAt(ix)))) {
* @param wordlist URL to the wordlist to use, or null for default
* @param maxWordLen maximum length of a word to use in the passphrase, <3 means use default
* @param ruc random upcase the first ruc letters, 0 or positive
* @param rruc random upcase the last rruc letters, 0 or positive
* @return number of passphrases generated, or -1 on error.
*/
public int generatePassphrases(int count, int strength, URL wordlist, int maxWordLen, int ruc) {
public int generatePassphrases(int count, int strength, URL wordlist, int maxWordLen, int ruc, int rruc) {
WordSet ws;
AbstractDRBG drbg;

Expand All @@ -430,6 +431,7 @@ public int generatePassphrases(int count, int strength, URL wordlist, int maxWor
return -1;
}
if (ruc < 0) ruc = 0;
if (rruc < 0) rruc = 0;

drbg = randman.getDRBG();
if (!(drbg.isOkay())) {
Expand Down Expand Up @@ -474,6 +476,16 @@ public int generatePassphrases(int count, int strength, URL wordlist, int maxWor
if (wrd == null) {
logger.warning("RandPassGen - fatal error in trying to randomly upcase a word");
return -1;
}
// if rruc <= 0 then this has no effect, we can randomly upcase both from the front and the back
// Debug - Original Below
// wrd = ws.reverseRandomUpcase(s, rruc, drbg);
// Debug - New below
wrd = ws.reverseRandomUpcase(wrd, rruc, drbg);

if (wrd == null) {
logger.warning("RandPassGen - fatal error in trying to randomly reverse upcase a word");
return -1;
}
// add word to the passphrase
sj.add(wrd);
Expand Down Expand Up @@ -706,6 +718,7 @@ private static OptionManager makeOptions() {
ret.addOption("decrypt", "Decrypt an encrypted key file using password", true, "-decrypt", null);
ret.addOption("enc", "Encrypt each key to a file using password (only for -k)", false, "-enc", null);
ret.addOption("randUpcase", "For passphrases, apply uppercase randomly to first N letters of each word", true, "-rcc", null);
ret.addOption("reverseRandUpcase", "For passphrases, apply uppercase randomly to last N letters of each word", true, "-rrcc", null);
return ret;
}

Expand Down Expand Up @@ -763,6 +776,7 @@ public static void main(String [] args) {
String decryptFilePath = opt.getValue("decrypt");
boolean enc = opt.getValueAsBoolean("enc");
int randUpcase = opt.getValueAsInt("randUpcase");
int reverseRandUpcase = opt.getValueAsInt("reverseRandUpcase");

// check for something to do
if (decryptFilePath != null) {
Expand Down Expand Up @@ -855,6 +869,16 @@ public static void main(String [] args) {
rpg.getLogger().info("Random upcase enabled for first " + randUpcase + " letters of passphrases");
}

// figure out if we are doing reverse random upcasing
if (reverseRandUpcase <= 0) {
reverseRandUpcase = 0;
} else {
if (verbose) {
System.err.println("Using reverse random upcase on last " + reverseRandUpcase + " letters.");
}
rpg.getLogger().info("Random upcase enabled for last " + reverseRandUpcase + " letters of passphrases");
}

// get the URL for the wordlist
URL ppURL = null;
if (ppurl != null && ppurl.length() > 0) {
Expand All @@ -864,7 +888,7 @@ public static void main(String [] args) {
rpg.getLogger().warning("RandPassGen - bad word list URL, exception: " + ue);
}
}
cnt = rpg.generatePassphrases(numPassphrases, strength, ppURL, maxWordLen, randUpcase);
cnt = rpg.generatePassphrases(numPassphrases, strength, ppURL, maxWordLen, randUpcase, reverseRandUpcase);
if (cnt <= 0) {
rpg.message("Failed to generate passphrases");
rpg.getLogger().warning("Tried to generate " + numPassphrases + " passphrases, but failed.");
Expand Down