-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
args="-Ddemo.log4j.propertie $@" | ||
mvn -e -q -o compile exec:java -Dexec.mainClass="org.jho.ace.Demo" -Dexec.args="$args" -Dexec.classpathScope=runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
log4j.rootLogger=INFO, stdout | ||
|
||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %X{url} %p %c - %m%n | ||
|
||
log4j.category.org.jho.ace=DEBUG | ||
log4j.category.org.jho.ace.cryptanalyzer=DEBUG | ||
|
||
log4j.category.org.jho.ace.genetic=INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2012 Photobucket | ||
*/ | ||
|
||
package org.jho.ace | ||
|
||
import org.jho.ace.ciphers.Cipher | ||
import org.jho.ace.cryptanalyzer.AStarCryptanalyzer | ||
import org.jho.ace.cryptanalyzer.BFSCryptanalyzer | ||
import org.jho.ace.cryptanalyzer.GeneticCryptanalyzer | ||
import org.jho.ace.cryptanalyzer.SACryptanalyzer | ||
import org.jho.ace.util.Configureable | ||
import org.jho.ace.util._ | ||
|
||
class Demo extends Configureable { | ||
def run(args:Map[String, String]) { | ||
val plaintext = language.sample(200) | ||
val keyword = args.getOrElse("keyword", "KEYWORD") | ||
|
||
val cipher:Cipher = Class.forName("org.jho.ace.ciphers."+args.getOrElse("cipher", "Vigenere")) | ||
.newInstance | ||
.asInstanceOf[Cipher] | ||
|
||
//TODO: using reflection with scala default args is not working well | ||
//this will have to do for now | ||
val cryptanalyzer = args.getOrElse("cryptanalyzer", "BFS") match { | ||
case "AStar" => new AStarCryptanalyzer | ||
case "BFS" => new BFSCryptanalyzer | ||
case "SA" => new SACryptanalyzer | ||
case "Genetic" => new GeneticCryptanalyzer | ||
} | ||
|
||
val startTime = System.currentTimeMillis | ||
val ciphertext = cipher.encrypt(keyword, plaintext) | ||
println("Cryptanalyzing using "+cryptanalyzer.getClass.getSimpleName+"...") | ||
val result = cryptanalyzer.decrypt(ciphertext, cipher) | ||
|
||
println("----------------") | ||
println("Result: " + result.keyword) | ||
println("Accuracy: " + (1-plaintext.distance(result.plainText))) | ||
println("Took: " + (System.currentTimeMillis - startTime)/1000 + " seconds") | ||
} | ||
} | ||
|
||
object Demo extends CommandLine { | ||
def main(args:Array[String]) = { | ||
new Demo().run(parseArgs(args)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2012 Photobucket | ||
*/ | ||
|
||
package org.jho.ace.util | ||
|
||
trait CommandLine { | ||
def parseArgs(argv:Array[String]):Map[String, String] = { | ||
//seperate options from argumetns | ||
val (opts, args) = argv.partition{ _.startsWith("-") } | ||
|
||
//turning options array into map | ||
return Map() ++ opts.map{ x => | ||
val pair = x.split("-{1,2}")(1).split("=") | ||
if(pair.length ==1) (pair(0), "true") else (pair(0), pair(1)) | ||
} | ||
|
||
//use the option values | ||
//val verbose = optsMap.getOrElse("v", "false").toBoolean | ||
//val number = optsMap.getOrElse("n", "0").toInt | ||
} | ||
} |