Add second year
This commit is contained in:
3
second/semester1/CT255/Assessment/CT255-Assignment-2/.idea/.gitignore
generated
vendored
Normal file
3
second/semester1/CT255/Assessment/CT255-Assignment-2/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
second/semester1/CT255/Assessment/CT255-Assignment-2/.idea/misc.xml
generated
Normal file
6
second/semester1/CT255/Assessment/CT255-Assignment-2/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="semeru-18" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
second/semester1/CT255/Assessment/CT255-Assignment-2/.idea/modules.xml
generated
Normal file
8
second/semester1/CT255/Assessment/CT255-Assignment-2/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/CT255-Assignment-2.iml" filepath="$PROJECT_DIR$/CT255-Assignment-2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Binary file not shown.
@ -0,0 +1,123 @@
|
||||
import java.util.HashMap;
|
||||
|
||||
/* CT255 Assignment 2
|
||||
* This class provides functionality to build rainbow tables (with a different reduction function per round) for 8 character long strings, which
|
||||
consist of the symbols "a .. z", "A .. Z", "0 .. 9", "!" and "#" (64 symbols in total).
|
||||
Properly used, it creates the following value pairs (start value - end value) after 10,000 iterations of hashFunction() and reductionFunction():
|
||||
start value - end value
|
||||
Kermit12 lsXcRAuN
|
||||
Modulus! L2rEsY8h
|
||||
Pigtail1 R0NoLf0w
|
||||
GalwayNo 9PZjwF5c
|
||||
Trumpets !oeHRZpK
|
||||
HelloPat dkMPG7!U
|
||||
pinky##! eDx58HRq
|
||||
01!19!56 vJ90ePjV
|
||||
aaaaaaaa rLtVvpQS
|
||||
aaaaaaaa klQ6IeQJ
|
||||
|
||||
|
||||
*
|
||||
* @author Michael Schukat
|
||||
* @version 1.0
|
||||
*/
|
||||
public class RainbowTable
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
long res = 0;
|
||||
|
||||
// String array of the known passwords
|
||||
String[] passwords = {"Kermit12", "Modulus!", "Pigtail1", "GalwayNo", "Trumpets", "HelloPat", "pinky##!", "01!19!56", "aaaaaaaa", "aaaaaaaa"};
|
||||
|
||||
HashMap<String, String> rainbowTable = new HashMap<>(); // declaring a HashTable that i'll use to store the password : hash pairs
|
||||
|
||||
|
||||
// looping through the passwords array
|
||||
for (String start : passwords) {
|
||||
if (start.length() != 8) {
|
||||
System.out.println("Input " + start + " must be 8 characters long - Exit");
|
||||
}
|
||||
else {
|
||||
String hash = start; // declaring a String hash that will hold the final reduced hash of a given password
|
||||
|
||||
// hashing & reducing the start String 10000 times.
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
hash = reductionFunction((hashFunction(hash)), i);
|
||||
}
|
||||
|
||||
// adding the password & its hash value to the rainbowTable HashMap
|
||||
rainbowTable.put(start, hash);
|
||||
}
|
||||
}
|
||||
// printing out the contents of the rainbowTable
|
||||
System.out.println(rainbowTable);
|
||||
|
||||
// chain lookup section
|
||||
// long array of the 4 hashes to be searched for
|
||||
long[] hashes = {895210601874431214L, 750105908431234638L, 111111111115664932L, 977984261343652499L};
|
||||
|
||||
// for each loop that loops through each hash in the array of hashes
|
||||
for (long hash : hashes) {
|
||||
|
||||
// looping 10000 times to search for the password - this will function as our max number of iterations, as 10000 iterations should just take use back to where we started.
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
// reducing the hash
|
||||
String str = reductionFunction(hash, i);
|
||||
System.out.println(hash + " : " + str);
|
||||
// checking if the reduced hash is a value (final plaintext) in the rainbowTable HashMap
|
||||
if (rainbowTable.containsValue(str)) {
|
||||
System.out.println("Found password " + str + " for hash value " + hash); // printing the found password
|
||||
break; // breaking out of the for loop
|
||||
}
|
||||
else {
|
||||
hash = hashFunction(str); // hashing str before continuing the for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long hashFunction(String s){
|
||||
long ret = 0;
|
||||
int i;
|
||||
long[] hashA = new long[]{1, 1, 1, 1};
|
||||
|
||||
String filler, sIn;
|
||||
|
||||
int DIV = 65536;
|
||||
|
||||
filler = new String("ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH");
|
||||
|
||||
sIn = s + filler; // Add characters, now have "<input>HABCDEF..."
|
||||
sIn = sIn.substring(0, 64); // Limit string to first 64 characters
|
||||
|
||||
for (i = 0; i < sIn.length(); i++) {
|
||||
char byPos = sIn.charAt(i); // get i'th character
|
||||
hashA[0] += (byPos * 17111); // Note: A += B means A = A + B
|
||||
hashA[1] += (hashA[0] + byPos * 31349);
|
||||
hashA[2] += (hashA[1] - byPos * 101302);
|
||||
hashA[3] += (byPos * 79001);
|
||||
}
|
||||
|
||||
ret = (hashA[0] + hashA[2]) + (hashA[1] * hashA[3]);
|
||||
if (ret < 0) ret *= -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static String reductionFunction(long val, int round) { // Note that for the first function call "round" has to be 0,
|
||||
String car, out; // and has to be incremented by one with every subsequent call.
|
||||
int i; // I.e. "round" created variations of the reduction function.
|
||||
char dat;
|
||||
|
||||
car = new String("0123456789ABCDEFGHIJKLMNOPQRSTUNVXYZabcdefghijklmnopqrstuvwxyz!#");
|
||||
out = new String("");
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
val -= round;
|
||||
dat = (char) (val % 63);
|
||||
val = val / 83;
|
||||
out = out + car.charAt(dat);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
\addtolength{\hoffset}{-2.25cm}
|
||||
\addtolength{\textwidth}{4.5cm}
|
||||
\addtolength{\voffset}{-3.25cm}
|
||||
\addtolength{\textheight}{5cm}
|
||||
\setlength{\parskip}{0pt}
|
||||
\setlength{\parindent}{0in}
|
||||
|
||||
%----------------------------------------------------------------------------------------
|
||||
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
|
||||
%----------------------------------------------------------------------------------------
|
||||
|
||||
\usepackage{blindtext} % Package to generate dummy text
|
||||
\usepackage{charter} % Use the Charter font
|
||||
\usepackage[utf8]{inputenc} % Use UTF-8 encoding
|
||||
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
|
||||
\usepackage[english, ngerman]{babel} % Language hyphenation and typographical rules
|
||||
\usepackage{amsthm, amsmath, amssymb} % Mathematical typesetting
|
||||
\usepackage{float} % Improved interface for floating objects
|
||||
\usepackage[final, colorlinks = true,
|
||||
linkcolor = black,
|
||||
citecolor = black]{hyperref} % For hyperlinks in the PDF
|
||||
\usepackage{graphicx, multicol} % Enhanced support for graphics
|
||||
\usepackage{xcolor} % Driver-independent color extensions
|
||||
\usepackage{marvosym, wasysym} % More symbols
|
||||
\usepackage{rotating} % Rotation tools
|
||||
\usepackage{censor} % Facilities for controlling restricted text
|
||||
\usepackage{listings, style/lstlisting} % Environment for non-formatted code, !uses style file!
|
||||
\usepackage{pseudocode} % Environment for specifying algorithms in a natural way
|
||||
\usepackage{style/avm} % Environment for f-structures, !uses style file!
|
||||
\usepackage{booktabs} % Enhances quality of tables
|
||||
\usepackage{tikz-qtree} % Easy tree drawing tool
|
||||
\tikzset{every tree node/.style={align=center,anchor=north},
|
||||
level distance=2cm} % Configuration for q-trees
|
||||
\usepackage{style/btree} % Configuration for b-trees and b+-trees, !uses style file!
|
||||
\usepackage[backend=biber,style=numeric,
|
||||
sorting=nyt]{biblatex} % Complete reimplementation of bibliographic facilities
|
||||
\addbibresource{ecl.bib}
|
||||
\usepackage{csquotes} % Context sensitive quotation facilities
|
||||
\usepackage[yyyymmdd]{datetime} % Uses YEAR-MONTH-DAY format for dates
|
||||
\renewcommand{\dateseparator}{-} % Sets dateseparator to '-'
|
||||
\usepackage{fancyhdr} % Headers and footers
|
||||
\pagestyle{fancy} % All pages have headers and footers
|
||||
\fancyhead{}\renewcommand{\headrulewidth}{0pt} % Blank out the default header
|
||||
\fancyfoot[L]{} % Custom footer text
|
||||
\fancyfoot[C]{} % Custom footer text
|
||||
\fancyfoot[R]{\thepage} % Custom footer text
|
||||
\newcommand{\note}[1]{\marginpar{\scriptsize \textcolor{red}{#1}}} % Enables comments in red on margin
|
||||
|
||||
%----------------------------------------------------------------------------------------
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
Binary file not shown.
@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" standalone="yes"?>
|
||||
<!-- logreq request file -->
|
||||
<!-- logreq version 1.0 / dtd version 1.0 -->
|
||||
<!-- Do not edit this file! -->
|
||||
<!DOCTYPE requests [
|
||||
<!ELEMENT requests (internal | external)*>
|
||||
<!ELEMENT internal (generic, (provides | requires)*)>
|
||||
<!ELEMENT external (generic, cmdline?, input?, output?, (provides | requires)*)>
|
||||
<!ELEMENT cmdline (binary, (option | infile | outfile)*)>
|
||||
<!ELEMENT input (file)+>
|
||||
<!ELEMENT output (file)+>
|
||||
<!ELEMENT provides (file)+>
|
||||
<!ELEMENT requires (file)+>
|
||||
<!ELEMENT generic (#PCDATA)>
|
||||
<!ELEMENT binary (#PCDATA)>
|
||||
<!ELEMENT option (#PCDATA)>
|
||||
<!ELEMENT infile (#PCDATA)>
|
||||
<!ELEMENT outfile (#PCDATA)>
|
||||
<!ELEMENT file (#PCDATA)>
|
||||
<!ATTLIST requests
|
||||
version CDATA #REQUIRED
|
||||
>
|
||||
<!ATTLIST internal
|
||||
package CDATA #REQUIRED
|
||||
priority (9) #REQUIRED
|
||||
active (0 | 1) #REQUIRED
|
||||
>
|
||||
<!ATTLIST external
|
||||
package CDATA #REQUIRED
|
||||
priority (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8) #REQUIRED
|
||||
active (0 | 1) #REQUIRED
|
||||
>
|
||||
<!ATTLIST provides
|
||||
type (static | dynamic | editable) #REQUIRED
|
||||
>
|
||||
<!ATTLIST requires
|
||||
type (static | dynamic | editable) #REQUIRED
|
||||
>
|
||||
<!ATTLIST file
|
||||
type CDATA #IMPLIED
|
||||
>
|
||||
]>
|
||||
<requests version="1.0">
|
||||
<internal package="biblatex" priority="9" active="1">
|
||||
<generic>latex</generic>
|
||||
<provides type="dynamic">
|
||||
<file>main.bcf</file>
|
||||
</provides>
|
||||
<requires type="dynamic">
|
||||
<file>main.bbl</file>
|
||||
</requires>
|
||||
<requires type="static">
|
||||
<file>blx-dm.def</file>
|
||||
<file>blx-compat.def</file>
|
||||
<file>biblatex.def</file>
|
||||
<file>standard.bbx</file>
|
||||
<file>numeric.bbx</file>
|
||||
<file>numeric.cbx</file>
|
||||
<file>biblatex.cfg</file>
|
||||
<file>german.lbx</file>
|
||||
<file>ngerman.lbx</file>
|
||||
<file>english.lbx</file>
|
||||
</requires>
|
||||
</internal>
|
||||
<external package="biblatex" priority="5" active="1">
|
||||
<generic>biber</generic>
|
||||
<cmdline>
|
||||
<binary>biber</binary>
|
||||
<infile>main</infile>
|
||||
</cmdline>
|
||||
<input>
|
||||
<file>main.bcf</file>
|
||||
</input>
|
||||
<output>
|
||||
<file>main.bbl</file>
|
||||
</output>
|
||||
<provides type="dynamic">
|
||||
<file>main.bbl</file>
|
||||
</provides>
|
||||
<requires type="dynamic">
|
||||
<file>main.bcf</file>
|
||||
</requires>
|
||||
<requires type="editable">
|
||||
<file>ecl.bib</file>
|
||||
</requires>
|
||||
</external>
|
||||
</requests>
|
@ -0,0 +1,281 @@
|
||||
\documentclass[a4paper]{article}
|
||||
\input{head}
|
||||
\begin{document}
|
||||
|
||||
%-------------------------------
|
||||
% TITLE SECTION
|
||||
%-------------------------------
|
||||
|
||||
\fancyhead[C]{}
|
||||
\hrule \medskip % Upper rule
|
||||
\begin{minipage}{0.295\textwidth}
|
||||
\raggedright
|
||||
\footnotesize
|
||||
Andrew Hayes \hfill\\
|
||||
21321503 \hfill\\
|
||||
a.hayes18@nuigalway.ie
|
||||
\end{minipage}
|
||||
\begin{minipage}{0.4\textwidth}
|
||||
\centering
|
||||
\large
|
||||
CT255 Assignment 2\\
|
||||
\normalsize
|
||||
Rainbow Tables\\
|
||||
\end{minipage}
|
||||
\begin{minipage}{0.295\textwidth}
|
||||
\raggedleft
|
||||
\today\hfill\\
|
||||
\end{minipage}
|
||||
\medskip\hrule
|
||||
\bigskip
|
||||
|
||||
%-------------------------------
|
||||
% CONTENTS
|
||||
%-------------------------------
|
||||
|
||||
\section{Problem 1}
|
||||
\subsection{Code}
|
||||
\begin{lstlisting}[language=Java]
|
||||
import java.util.HashMap;
|
||||
|
||||
/* CT255 Assignment 2
|
||||
* This class provides functionality to build rainbow tables (with a different reduction function per round) for 8 character long strings, which
|
||||
consist of the symbols "a .. z", "A .. Z", "0 .. 9", "!" and "#" (64 symbols in total).
|
||||
Properly used, it creates the following value pairs (start value - end value) after 10,000 iterations of hashFunction() and reductionFunction():
|
||||
start value - end value
|
||||
Kermit12 lsXcRAuN
|
||||
Modulus! L2rEsY8h
|
||||
Pigtail1 R0NoLf0w
|
||||
GalwayNo 9PZjwF5c
|
||||
Trumpets !oeHRZpK
|
||||
HelloPat dkMPG7!U
|
||||
pinky##! eDx58HRq
|
||||
01!19!56 vJ90ePjV
|
||||
aaaaaaaa rLtVvpQS
|
||||
aaaaaaaa klQ6IeQJ
|
||||
|
||||
|
||||
*
|
||||
* @author Michael Schukat
|
||||
* @version 1.0
|
||||
*/
|
||||
public class RainbowTable
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
long res = 0;
|
||||
|
||||
// String array of the known passwords
|
||||
String[] passwords = {"Kermit12", "Modulus!", "Pigtail1", "GalwayNo", "Trumpets", "HelloPat", "pinky##!", "01!19!56", "aaaaaaaa", "aaaaaaaa"};
|
||||
|
||||
HashMap<String, String> rainbowTable = new HashMap<>(); // declaring a HashTable that i'll use to store the password : hash pairs
|
||||
|
||||
|
||||
// looping through the passwords array
|
||||
for (String start : passwords) {
|
||||
if (start.length() != 8) {
|
||||
System.out.println("Input " + start + " must be 8 characters long - Exit");
|
||||
}
|
||||
else {
|
||||
String hash = start; // declaring a String hash that will hold the final reduced hash of a given password
|
||||
|
||||
// hashing & reducing the start String 10000 times.
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
hash = reductionFunction((hashFunction(hash)), i);
|
||||
}
|
||||
|
||||
// adding the password & its hash value to the rainbowTable HashMap
|
||||
rainbowTable.put(start, hash);
|
||||
}
|
||||
}
|
||||
// printing out the contents of the rainbowTable
|
||||
System.out.println(rainbowTable);
|
||||
}
|
||||
|
||||
private static long hashFunction(String s){
|
||||
long ret = 0;
|
||||
int i;
|
||||
long[] hashA = new long[]{1, 1, 1, 1};
|
||||
|
||||
String filler, sIn;
|
||||
|
||||
int DIV = 65536;
|
||||
|
||||
filler = new String("ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH");
|
||||
|
||||
sIn = s + filler; // Add characters, now have "<input>HABCDEF..."
|
||||
sIn = sIn.substring(0, 64); // // Limit string to first 64 characters
|
||||
|
||||
for (i = 0; i < sIn.length(); i++) {
|
||||
char byPos = sIn.charAt(i); // get i'th character
|
||||
hashA[0] += (byPos * 17111); // Note: A += B means A = A + B
|
||||
hashA[1] += (hashA[0] + byPos * 31349);
|
||||
hashA[2] += (hashA[1] - byPos * 101302);
|
||||
hashA[3] += (byPos * 79001);
|
||||
}
|
||||
|
||||
ret = (hashA[0] + hashA[2]) + (hashA[1] * hashA[3]);
|
||||
if (ret < 0) ret *= -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static String reductionFunction(long val, int round) { // Note that for the first function call "round" has to be 0,
|
||||
String car, out; // and has to be incremented by one with every subsequent call.
|
||||
int i; // I.e. "round" created variations of the reduction function.
|
||||
char dat;
|
||||
|
||||
car = new String("0123456789ABCDEFGHIJKLMNOPQRSTUNVXYZabcdefghijklmnopqrstuvwxyz!#");
|
||||
out = new String("");
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
val -= round;
|
||||
dat = (char) (val % 63);
|
||||
val = val / 83;
|
||||
out = out + car.charAt(dat);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
\end{lstlisting}
|
||||
|
||||
\subsection{Output}
|
||||
\includegraphics[width = 16cm]{image.png}
|
||||
|
||||
\bigskip
|
||||
|
||||
%------------------------------------------------
|
||||
|
||||
\section{Problem 2}
|
||||
\subsection{Code}
|
||||
\begin{lstlisting}[language=java]
|
||||
import java.util.HashMap;
|
||||
|
||||
/* CT255 Assignment 2
|
||||
* This class provides functionality to build rainbow tables (with a different reduction function per round) for 8 character long strings, which
|
||||
consist of the symbols "a .. z", "A .. Z", "0 .. 9", "!" and "#" (64 symbols in total).
|
||||
Properly used, it creates the following value pairs (start value - end value) after 10,000 iterations of hashFunction() and reductionFunction():
|
||||
start value - end value
|
||||
Kermit12 lsXcRAuN
|
||||
Modulus! L2rEsY8h
|
||||
Pigtail1 R0NoLf0w
|
||||
GalwayNo 9PZjwF5c
|
||||
Trumpets !oeHRZpK
|
||||
HelloPat dkMPG7!U
|
||||
pinky##! eDx58HRq
|
||||
01!19!56 vJ90ePjV
|
||||
aaaaaaaa rLtVvpQS
|
||||
aaaaaaaa klQ6IeQJ
|
||||
|
||||
|
||||
*
|
||||
* @author Michael Schukat
|
||||
* @version 1.0
|
||||
*/
|
||||
public class RainbowTable
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
long res = 0;
|
||||
|
||||
// String array of the known passwords
|
||||
String[] passwords = {"Kermit12", "Modulus!", "Pigtail1", "GalwayNo", "Trumpets", "HelloPat", "pinky##!", "01!19!56", "aaaaaaaa", "aaaaaaaa"};
|
||||
|
||||
HashMap<String, String> rainbowTable = new HashMap<>(); // declaring a HashTable that i'll use to store the password : hash pairs
|
||||
|
||||
|
||||
// looping through the passwords array
|
||||
for (String start : passwords) {
|
||||
if (start.length() != 8) {
|
||||
System.out.println("Input " + start + " must be 8 characters long - Exit");
|
||||
}
|
||||
else {
|
||||
String hash = start; // declaring a String hash that will hold the final reduced hash of a given password
|
||||
|
||||
// hashing & reducing the start String 10000 times.
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
hash = reductionFunction((hashFunction(hash)), i);
|
||||
}
|
||||
|
||||
// adding the password & its hash value to the rainbowTable HashMap
|
||||
rainbowTable.put(start, hash);
|
||||
}
|
||||
}
|
||||
// printing out the contents of the rainbowTable
|
||||
System.out.println(rainbowTable);
|
||||
|
||||
// chain lookup section
|
||||
// long array of the 4 hashes to be searched for
|
||||
long[] hashes = {895210601874431214L, 750105908431234638L, 111111111115664932L, 977984261343652499L};
|
||||
|
||||
// for each loop that loops through each hash in the array of hashes
|
||||
for (long hash : hashes) {
|
||||
|
||||
// looping 10000 times to search for the password - this will function as our max number of iterations, as 10000 iterations should just take use back to where we started.
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
// reducing the hash
|
||||
String str = reductionFunction(hash, i);
|
||||
// checking if the reduced hash is a key (password) in the rainbowTable HashMap
|
||||
if (rainbowTable.containsValue(str)) {
|
||||
System.out.println("Found password " + str + " for hash value " + hash); // printing the found password
|
||||
break; // breaking out of the for loop
|
||||
}
|
||||
else {
|
||||
hash = hashFunction(str); // hashing str before continuing the for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long hashFunction(String s){
|
||||
long ret = 0;
|
||||
int i;
|
||||
long[] hashA = new long[]{1, 1, 1, 1};
|
||||
|
||||
String filler, sIn;
|
||||
|
||||
int DIV = 65536;
|
||||
|
||||
filler = new String("ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH");
|
||||
|
||||
sIn = s + filler; // Add characters, now have "<input>HABCDEF..."
|
||||
sIn = sIn.substring(0, 64); // // Limit string to first 64 characters
|
||||
|
||||
for (i = 0; i < sIn.length(); i++) {
|
||||
char byPos = sIn.charAt(i); // get i'th character
|
||||
hashA[0] += (byPos * 17111); // Note: A += B means A = A + B
|
||||
hashA[1] += (hashA[0] + byPos * 31349);
|
||||
hashA[2] += (hashA[1] - byPos * 101302);
|
||||
hashA[3] += (byPos * 79001);
|
||||
}
|
||||
|
||||
ret = (hashA[0] + hashA[2]) + (hashA[1] * hashA[3]);
|
||||
if (ret < 0) ret *= -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static String reductionFunction(long val, int round) { // Note that for the first function call "round" has to be 0,
|
||||
String car, out; // and has to be incremented by one with every subsequent call.
|
||||
int i; // I.e. "round" created variations of the reduction function.
|
||||
char dat;
|
||||
|
||||
car = new String("0123456789ABCDEFGHIJKLMNOPQRSTUNVXYZabcdefghijklmnopqrstuvwxyz!#");
|
||||
out = new String("");
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
val -= round;
|
||||
dat = (char) (val % 63);
|
||||
val = val / 83;
|
||||
out = out + car.charAt(dat);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
\end{lstlisting}
|
||||
\subsection{Output}
|
||||
I couldn't actually find a password match with the above code, and I'm not sure why. My current guess would be that the reduction function wasn't being called properly, as everything else \textit{seemed} to be working as expected. I didn't call the reduction more than 10,000 times as that would theoretically just lead me back to the same place in the chain. I think that my problem is with the passing of the integer \verb|i| to the reduction function, as I think that I correctly implemented the rest of the steps for performing a chain lookup - I input a hash value, reduce it, check if the reduced form is in the list of final plaintexts (the ``Values'' in the HashMap), and if so break out of the loop (but this never occurs), assigning the relevant ``Key'' from the HashMap as the original plaintext password that produced the original input hash. Otherwise, I continue until I'm back at the same place in the chain after the 10,000\textsuperscript{th} iteration, where the code gives up.
|
||||
|
||||
\bigskip
|
||||
|
||||
\includegraphics[width = 16cm]{image.png}
|
||||
\end{document}
|
@ -0,0 +1,165 @@
|
||||
% avm.sty -- for attribute-value matrices -- mar 29, 1992; rev. dec 6, 1993
|
||||
% (c) 1992 christopher manning (manning@csli.stanford.edu) -- see avm.doc.tex
|
||||
|
||||
\newif\ifavmactive\newif\ifavmsorted\newif\ifavmlabeled
|
||||
\newif\ifavmcenter\newif\ifavmbottom
|
||||
\newif\ifavmbottomright\newif\ifavmtopleft\newif\ifavmtopright
|
||||
|
||||
\newdimen\avmdimen
|
||||
\newbox\avmboxone\newbox\avmboxthree
|
||||
|
||||
\def\avmoptions#1{\avmactivefalse\avmsortedfalse\avmlabeledfalse
|
||||
\avmcenterfalse\avmbottomfalse
|
||||
\avmbottomrightfalse\avmtopleftfalse\avmtoprightfalse
|
||||
\def\more{#1}\ifx\more\empty\else\avmjoptions#1,\@nil\fi}
|
||||
\def\avmjoptions#1,#2\@nil{\def\more{#2}\csname avm#1true\endcsname
|
||||
\ifx\more\empty\else\avmjoptions#2\@nil\fi}
|
||||
|
||||
|
||||
\def\avmfont#1{\def\avmjfont{#1}}
|
||||
\def\avmjfont{}
|
||||
|
||||
\def\avmvalfont#1{\def\avmjvalfont{#1}}
|
||||
\def\avmjvalfont{}
|
||||
|
||||
\def\avmsortfont#1{\def\avmjsortfont{#1}}
|
||||
\def\avmjsortfont{}
|
||||
|
||||
\def\avmhskip#1{\def\avmjhskip{#1}}
|
||||
\def\avmjhskip{1em}
|
||||
|
||||
\def\avmbskip#1{\def\avmjbskip{#1}}
|
||||
\def\avmjbskip{0em}
|
||||
|
||||
\def\avmvskip#1{\def\avmjvskip{#1}}
|
||||
\def\avmjvskip{0.385ex}%was .3875
|
||||
|
||||
|
||||
\def\avmjprolog#1{$\mskip-\thinmuskip
|
||||
\left#1\hskip\avmjbskip\vcenter\bgroup\vskip\avmjvskip
|
||||
\ialign\bgroup\avmjfont
|
||||
\strut ##\unskip\hfil
|
||||
&&\hskip\avmjhskip\avmjvalfont ##\unskip\hfil\cr}
|
||||
\def\avmjpostlog#1{\crcr\egroup\vskip\avmjvskip\egroup
|
||||
\hskip\avmjbskip\right#1\mskip-\thinmuskip$\ignorespaces}
|
||||
|
||||
|
||||
\def\avmjcatcode{\let\lparen=(\let\rparen=)\catcode`\[=13\catcode`\]=13
|
||||
\catcode`\<=13\catcode`\@=13\catcode`\(=13\catcode`\)=13
|
||||
\catcode`\>=13\catcode`\|=13}
|
||||
|
||||
{\avmjcatcode % new group: redefine above catcodes as active
|
||||
|
||||
\gdef\specialavm{\avmjcatcode
|
||||
\def({\avmjprolog\lparen}%
|
||||
\def){\avmjpostlog\rparen}%
|
||||
\def<{\avmjprolog\langle}%
|
||||
\def>{\avmjpostlog\rangle}%
|
||||
\ifavmsorted
|
||||
\def[##1{\setbox\avmboxthree=\hbox{\avmjsortfont##1\/}\setbox2=\hbox
|
||||
\bgroup\avmjprolog\lbrack}%
|
||||
\def]{\avmjpostlog\rbrack\egroup\avmjsort}%
|
||||
\else\ifavmlabeled
|
||||
\def[##1{\def\more{##1}\setbox2=\hbox\bgroup\avmjprolog[}%
|
||||
\def]{\avmjpostlog]\egroup\node{\more}{\box2}}%
|
||||
\else
|
||||
\def[{\avmjprolog\lbrack}%
|
||||
\def]{\avmjpostlog\rbrack}%
|
||||
\fi\fi
|
||||
%
|
||||
\def\<{$\langle$}\def\>{$\rangle$}%
|
||||
\def\({\lparen}\def\){\rparen}%
|
||||
\def\[{\lbrack}\def\]{\rbrack}%
|
||||
\def|{$\,\vert\,$}%
|
||||
\def@##1{\avmbox{##1}}%
|
||||
} % end defn of \specialavm
|
||||
} % restore active catcodes
|
||||
|
||||
|
||||
\long\def\avm{\begingroup
|
||||
\ifavmactive\specialavm
|
||||
\else
|
||||
\def\({\avmjprolog(}%
|
||||
\def\){\avmjpostlog)}%
|
||||
\def\<{\avmjprolog\langle}%
|
||||
\def\>{\avmjpostlog\rangle}%
|
||||
%
|
||||
\ifavmsorted
|
||||
\def\[##1{\setbox\avmboxthree=\hbox{\avmjsortfont##1\/}\setbox
|
||||
2=\hbox\bgroup\avmjprolog[}%
|
||||
\def\]{\avmjpostlog]\egroup\avmjsort}%
|
||||
\else\ifavmlabeled
|
||||
\def\[##1{\def\more{##1}\setbox2=\hbox\bgroup\avmjprolog[}%
|
||||
\def\]{\avmjpostlog]\egroup\node{\more}{\box2}}%
|
||||
\else
|
||||
\def\[{\avmjprolog[}%
|
||||
\def\]{\avmjpostlog]}%
|
||||
\fi\fi
|
||||
%
|
||||
\def\|{$\,\vert\,$}%
|
||||
\def\@##1{\avmbox{##1}}%
|
||||
\fi % end not active
|
||||
%
|
||||
\ifx\LaTeX\undefined\def\\{\cr}% running under TeX
|
||||
\else \def\\{\@tabularcr}% Leverage off LaTeX's \\*[dimen] options
|
||||
\fi
|
||||
\def\!{\node}%
|
||||
\long\def\avmjsort{\dimen2=\ht2\advance\dimen2 by -.25\baselineskip
|
||||
\global\dimen\avmdimen=\wd\avmboxthree
|
||||
\ifavmtopleft \raise\dimen2\llap{\box\avmboxthree}\box2%
|
||||
\else\ifavmtopright \box2\raise\dimen2\box\avmboxthree%
|
||||
\else\ifavmbottomright \box2\lower\dimen2\box\avmboxthree%
|
||||
\else \lower\dimen2\llap{\box\avmboxthree}\box2%
|
||||
\fi\fi\fi}%
|
||||
\long\def\sort##1##2{\setbox2=\hbox{##2}\setbox
|
||||
\avmboxthree=\hbox{\avmjsortfont##1\/}\dimen2=\ht2
|
||||
\advance\dimen2 by -.25\baselineskip
|
||||
\ifavmtopleft \raise\dimen2\box\avmboxthree\box2%
|
||||
\else\ifavmtopright \box2\raise\dimen2\box\avmboxthree%
|
||||
\else\ifavmbottomright \box2\lower\dimen2\box\avmboxthree%
|
||||
\else \lower\dimen2\box\avmboxthree\box2%
|
||||
\fi\fi\fi}%
|
||||
\long\def\osort##1##2{\setbox2=\hbox{##2}\setbox
|
||||
\avmboxthree=\hbox{\avmjsortfont ##1\/}\avmjsort}%
|
||||
\def\avml{\avmjprolog.}%
|
||||
\def\avmr{\avmjpostlog.}%
|
||||
\def\avmb##1{\node{##1}{\lbrack\;\rbrack}}%
|
||||
\def\avmd##1{\node{##1}{---}}%
|
||||
\def\q##1{\ifx ##1\{$\lbrace$\else
|
||||
\ifx ##1\}$\rbrace$\else
|
||||
\ifx ##1<$\langle$\else
|
||||
\ifx ##1>$\rangle$\fi \fi \fi \fi}%
|
||||
\def\{{\avmjprolog\lbrace}%
|
||||
\def\}{\avmjpostlog\rbrace}%
|
||||
\def\;{\hskip\avmjhskip}%
|
||||
\def\avmspan##1{\multispan2\strut ##1\expandafter\hfil}%
|
||||
\avmjfont
|
||||
\openup\avmjvskip
|
||||
\setbox\avmboxone=\hbox\bgroup\ignorespaces
|
||||
} % end defn of \avm
|
||||
|
||||
|
||||
\def\endavm{\egroup\ifvmode\leavevmode\fi % this if is useful!
|
||||
\ifavmsorted\null\hskip\dimen\avmdimen\fi
|
||||
\ifavmcenter
|
||||
\box\avmboxone
|
||||
\else \ifavmbottom
|
||||
\lower.575\baselineskip\hbox{\vbox{\box\avmboxone\null}}%
|
||||
\else
|
||||
% the next bit is ripped off from Emma's \evnup in lingmacros.sty
|
||||
\dimen2=\ht\avmboxone\advance\dimen2 by -.725\baselineskip
|
||||
\lower\dimen2\box\avmboxone
|
||||
\fi \fi \endgroup}
|
||||
|
||||
|
||||
% based on TeXbook exercise 21.3
|
||||
\def\avmbox#1{\setbox2=\hbox{$\scriptstyle #1$}\lower.2ex\vbox{\hrule
|
||||
\hbox{\vrule\kern1.25pt
|
||||
\vbox{\kern1.25pt\box2\kern1.25pt}\kern1.25pt\vrule}\hrule}}
|
||||
|
||||
% ============ COSTOM CONFIGURATION =============
|
||||
\avmfont{\sc}
|
||||
\avmoptions{sorted,active}
|
||||
\avmvalfont{\rm}
|
||||
\avmsortfont{\scriptsize\it}
|
||||
% ===============================================
|
@ -0,0 +1,131 @@
|
||||
%% Last Modified: Thu Oct 18 18:26:25 2007.
|
||||
|
||||
\NeedsTeXFormat{LaTeX2e}
|
||||
\ProvidesPackage{style/btree}
|
||||
\typeout{Document Style `weiw_BTree - Support drawing B+-Tree (ver 0.999)}
|
||||
|
||||
\RequirePackage{tikz}
|
||||
\RequirePackage{ifthen}
|
||||
|
||||
% use libraries
|
||||
\usetikzlibrary{arrows,shapes,decorations,matrix}
|
||||
|
||||
|
||||
%% global declaration
|
||||
\tikzstyle{btreeptr} = [draw, semithick, minimum height=2em]
|
||||
\tikzstyle{btreeval} = [draw, semithick, minimum size=2em]
|
||||
\tikzstyle{btreevale} = [draw,semithick, minimum size=2em]
|
||||
\tikzstyle{btlink} = [draw, semithick, ->, >=triangle 45]
|
||||
|
||||
%% macro
|
||||
%% helper macros
|
||||
\newcommand{\suppressemptystr}[1]{% leave blank for entries in leaf nodes
|
||||
\ifthenelse{\equal{#1}{}}%
|
||||
{%
|
||||
\relax%
|
||||
}%
|
||||
% Else
|
||||
{%
|
||||
#1\textsuperscript{*}%
|
||||
}%
|
||||
}%
|
||||
|
||||
\newcommand{\xyshift}[3]{% help to place the nodes
|
||||
\begin{scope}[xshift=#1, yshift=#2]
|
||||
#3
|
||||
\end{scope}%
|
||||
}
|
||||
|
||||
%% Common btree macros
|
||||
\newcommand{\btreelink}[2]{% #1: src node; #2: dest node;
|
||||
\draw[btlink] ([yshift=3pt] #1.south) -- (#2-b.north);
|
||||
}
|
||||
|
||||
\newcommand{\btreelinknorth}[2]{% #1: src node; #2: dest node;
|
||||
\draw[btlink] ([yshift=3pt] #1.south) -- (#2.north);
|
||||
}
|
||||
|
||||
\newcommand{\btreetriangle}[2]{% #1: node name; #2 text inside
|
||||
\node[anchor=north, regular polygon, regular polygon sides=3, draw] (#1) {#2};
|
||||
}
|
||||
|
||||
%%======================================================================
|
||||
%% btree with capacity = 4
|
||||
\newcommand{\btreeinodefour}[5]{%
|
||||
\matrix [ampersand replacement=\&] (#1)
|
||||
{
|
||||
\node[btreeptr] (#1-1) {\vphantom{1}}; \& \node[btreeval] (#1-a) {#2}; \&
|
||||
\node[btreeptr] (#1-2) {\vphantom{1}}; \& \node[btreeval] (#1-b) {#3}; \&
|
||||
\node[btreeptr] (#1-3) {\vphantom{1}}; \& \node[btreeval] (#1-c) {#4}; \&
|
||||
\node[btreeptr] (#1-4) {\vphantom{1}}; \& \node[btreeval] (#1-d) {#5}; \&
|
||||
\node[btreeptr] (#1-5) {\vphantom{1}}; \\
|
||||
};
|
||||
}
|
||||
\newcommand{\btreelnodefour}[5]{%
|
||||
\matrix [ampersand replacement=\&, outer sep=0pt, matrix anchor=north] (#1)
|
||||
{
|
||||
\node[btreevale] (#1-a) {\suppressemptystr{#2}}; \&
|
||||
\node[btreevale] (#1-b) {\suppressemptystr{#3}}; \&
|
||||
\node[btreevale] (#1-c) {\suppressemptystr{#4}}; \&
|
||||
\node[btreevale] (#1-d) {\suppressemptystr{#5}}; \\
|
||||
};
|
||||
}
|
||||
|
||||
%%======================================================================
|
||||
%% btree with capacity = 3
|
||||
\newcommand{\btreeinodethree}[4]{%
|
||||
\matrix [ampersand replacement=\&] (#1)
|
||||
{
|
||||
\node[btreeptr] (#1-1) {\vphantom{1}}; \& \node[btreeval] (#1-a) {#2}; \&
|
||||
\node[btreeptr] (#1-2) {\vphantom{1}}; \& \node[btreeval] (#1-b) {#3}; \&
|
||||
\node[btreeptr] (#1-3) {\vphantom{1}}; \& \node[btreeval] (#1-c) {#4}; \&
|
||||
\node[btreeptr] (#1-4) {\vphantom{1}}; \\
|
||||
};
|
||||
}
|
||||
\newcommand{\btreelnodethree}[4]{%
|
||||
\matrix [ampersand replacement=\&, outer sep=0pt, matrix anchor=north] (#1)
|
||||
{
|
||||
\node[btreevale] (#1-a) {\suppressemptystr{#2}}; \&
|
||||
\node[btreevale] (#1-b) {\suppressemptystr{#3}}; \&
|
||||
\node[btreevale] (#1-c) {\suppressemptystr{#4}}; \\
|
||||
};
|
||||
}
|
||||
|
||||
%%======================================================================
|
||||
%% btree with capacity = 2
|
||||
\newcommand{\btreeinodetwo}[4]{%
|
||||
\matrix [ampersand replacement=\&] (#1)
|
||||
{
|
||||
\node[btreeptr] (#1-1) {\vphantom{1}}; \& \node[btreeval] (#1-a) {#2}; \&
|
||||
\node[btreeptr] (#1-2) {\vphantom{1}}; \& \node[btreeval] (#1-b) {#3}; \&
|
||||
\node[btreeptr] (#1-3) {\vphantom{1}}; \\
|
||||
};
|
||||
}
|
||||
\newcommand{\btreelnodetwo}[3]{%
|
||||
\matrix [ampersand replacement=\&, outer sep=0pt, matrix anchor=north] (#1)
|
||||
{
|
||||
\node[btreevale] (#1-a) {\suppressemptystr{#2}}; \&
|
||||
\node[btreevale] (#1-b) {\suppressemptystr{#3}}; \\
|
||||
};
|
||||
}
|
||||
%%======================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
%% simple example
|
||||
% \begin{center}
|
||||
% \scalebox{0.7}{
|
||||
% \begin{tikzpicture}
|
||||
% %
|
||||
% \btreeinodefour{root}{13}{17}{24}{30};
|
||||
% \xyshift{-40mm}{-20mm}{\btreelnodefour{n1}{2}{3}{5}{7}}
|
||||
% \xyshift{-0mm}{-20mm}{\btreelnodefour{n2}{14}{16}{}{}}
|
||||
% \xyshift{40mm}{-20mm}{\btreelnodefour{n3}{19}{20}{22}{}}
|
||||
% \xyshift{80mm}{-20mm}{\btreelnodefour{n4}{24}{27}{29}{}}
|
||||
% \xyshift{120mm}{-20mm}{\btreelnodefour{n5}{33}{34}{38}{39}}
|
||||
% %
|
||||
% \foreach \x in {1,2,...,5} { \btreelink{root-\x}{n\x} }
|
||||
% \end{tikzpicture}
|
||||
% }
|
||||
% \end{center}
|
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
@ -0,0 +1,38 @@
|
||||
% Source: ss17_wissschreib (Eva)
|
||||
|
||||
\lstset{
|
||||
basicstyle=\ttfamily\scriptsize\mdseries,
|
||||
keywordstyle=\bfseries\color[rgb]{0.171875, 0.242188, 0.3125},
|
||||
identifierstyle=,
|
||||
commentstyle=\color[rgb]{0.257813, 0.15625, 0},
|
||||
stringstyle=\itshape\color[rgb]{0.0195313, 0.195313, 0.0117188},
|
||||
numbers=left,
|
||||
numberstyle=\tiny,
|
||||
stepnumber=1,
|
||||
breaklines=true,
|
||||
frame=none,
|
||||
showstringspaces=false,
|
||||
tabsize=4,
|
||||
backgroundcolor=\color[rgb]{0.98,0.98,0.98},
|
||||
captionpos=b,
|
||||
float=htbp,
|
||||
language=Python,
|
||||
xleftmargin=15pt,
|
||||
xrightmargin=15pt
|
||||
}
|
||||
|
||||
%(deutsche) Sonderzeichen
|
||||
\lstset{literate=%
|
||||
{Ä}{{\"A}}1
|
||||
{Ö}{{\"O}}1
|
||||
{Ü}{{\"U}}1
|
||||
{ä}{{\"a}}1
|
||||
{ö}{{\"o}}1
|
||||
{ü}{{\"u}}1
|
||||
{ß}{{\ss}}1
|
||||
}
|
||||
|
||||
%Verwendung im Text:
|
||||
%-> \begin{lstlisting}[language=Python,firstnumber=27] ... \end{lstlisting}
|
||||
%-> \begin{lstlisting}[language=Python,numbers=none] ... \end{lstlisting}
|
||||
%-> \lstinline[language=JAVA]{...}
|
Reference in New Issue
Block a user