Add second year

This commit is contained in:
2023-12-07 01:19:12 +00:00
parent 3291e5c79e
commit 3d12031ab8
1168 changed files with 431409 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="semeru-18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View 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>

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -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$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,50 @@
\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
%----------------------------------------------------------------------------------------

View File

@ -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="0">
<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="0">
<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>

View File

@ -0,0 +1,121 @@
\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 1\\
\normalsize
GDPR\\
\end{minipage}
\begin{minipage}{0.295\textwidth}
\raggedleft
\today\hfill\\
\end{minipage}
\medskip\hrule
\bigskip
%-------------------------------
% CONTENTS
%-------------------------------
\section{Problem 1}
\subsection{What is GDPR?}
The \textbf{General Data Protection Regulation (GDPR)} is a legal regulation in EU law pertaining to the protection of data within the European Union and the European Economic Area (EEA), and the protection of this data when it is transferred out of this region. GDPR applies to any organisation that is processing the personal data of individuals who are in the EEA, regardless of the location of said organisation or the citizenship / residence status of the individuals whose data is being processed. GDPR sets out several key principles in relation to the processing of personal data:
\begin{itemize}
\item \textbf{Lawfulness -} You must identify a \textit{lawful basis} under the GDPR for the processing of personal data.
\item \textbf{Fairness \& Transparency -} You must be open \& honest with the Data Subjects about how and why their data is being processed, and you must not use this data in a way that doesn't align with these methods.
\item \textbf{Purpose Limitation -} You must clearly state your purposes for processing the personal data of Data Subjects from the start, and may only use the data for different purpose if it is either compatible with your original purpose, you get \textit{consent}, or if you have a \textit{clear basis} in law.
\item \textbf{Data Minimisation -} The personal data you process must be \textit{adequate}, \textit{relevant}, and \textit{limited} only to what is necessary.
\item \textbf{Accuracy -} Personal data should not be incorrect or misleading.
\item \textbf{Storage Limitation -} You must not keep personal data for longer than you need it.
\item \textbf{Integrity \& Confidentiality -} You must take appropriate technical \& organisational measures to ensure that the personal data of data subjects remains \textit{secure}.
\item \textbf{Accountability -} You must be able to demonstrate your compliance with GDPR.
\end{itemize}
\bigbreak
All Data Processors (i.e., anyone who is responsible for the processing of personal information) are motivated to obey GDPR by threat of strict penalties. For particularly serious GDPR breaches, a Data Processor could be fined up to €20 million, or 4\% of the firm's global turnover. For less serious breaches, the Data Processor can be fined up to €10 million, or 2\% of the firm's global turnover.
\subsection{Why was GDPR introduced? What was the motivation for this legislation?}
GDPR was introduced with the aim of enhancing the rights \& control of individuals over their personal data and to simplify data processing regulations with regards to international businesses.
\bigbreak
As the processing of the personal data of individuals increases in the modern world with the advent of modern technology, it has became necessary to update the laws governing the processing of personal data to protect the interests of data subjects in an era of unprecedented data collection, surveillance, \& processing. GDPR sets out clear \& concise principles \& rules that determine who's personal data may be processed, what information this data may consist of, when it is acceptable to process it, where this data can be processed \& relocated to, why this data may or may not be processed, and how this data processing can be undertaken.
\bigbreak
The European Parliament adopted the GDPR in April 2016 to replace the then-outdated Data Protection Directive, which was first enacted in 1995.
There were 2 main issues with the Data Protection Directive that made it necessary to replace it:
\begin{enumerate}
\item Under EU law, a ``Directive'' is less strict than a ``Regulation''.
A Directive allows the EU member states to adapt \& change the law to fit the needs of their citizens, while a Regulation does not allow this.
A Regulation forces the member states to adopt it, and does not allow them to adapt or change it at all.
\item The Data Protection Directive was too outdated for the modern world.
It did not address how data is collected, stored, or transferred in the digital world, and thus largely failed to regulate digital data processing.
\end{enumerate}
\bigskip
%------------------------------------------------
\section{Problem 2}
This company needs to be extremely careful with their GDPR compliance, as they are handling some extremely sensitive personal information.
\newline\newline
With regards to the GDPR key principle of \textbf{Lawfulness}, I think that this website is in the clear.
Since the users are uploading their own data of their own volition, this gives the website a clear lawful basis for data processing - they have the \textit{consent} of the data subjects for the processing of their data.
\newline\newline
I do, however, have some concerns about the compliance of the company with GDPR key principle \textbf{Fairness \& Transparency}. The company is quite vague about how they process the personal data of the users, how the data is stored, etc.
There is no mention of any kind of Data Protection Notice that informs the user of the identity \& contact details of the Data Controller, the contact details of the Data Protection officer, the details of any data transfer out of of the EEA or the safeguards in place, the data retention period, or the individual's rights.
The only information that the Data Subjects really have is the purpose of the processing and (at least some of) the recipients of the data.
It's possible that other people are in receipt of the users' personal data as well, but there is no mention of this.
\bigbreak
The company should be in the clear with regards to \textbf{Purpose Limitation}, assuming that they are being fully open \& honest about their purposes for processing the data, and stick to these purposes, but if they are not doing this, then that is a massive issue.
\newline\newline
The principle of \textbf{Data Minimisation} is a bit more of a grey area for this website.
It's hard to say what data is and isn't adequate \& relevant to the purpose of "keeping in touch".
Personally, I would be of the opinion that absolutely none of the data mentioned is relevant for the purposes of "keeping in touch", but it is plausible that some people would feel otherwise.
It could be problematic for the company that they allow the users to upload pretty much whatever they want, as the company may end up in possession of a lot of irrelevant data that the users uploaded.
The company needs to be extremely careful with receiving data that they didn't expect to receive, which may or may not be relevant to the purposes of the company.
\newline\newline
The principle of \textbf{Accuracy} is another potentially problematic one for this company.
The company must take all reasonable steps to ensure that the personal data that they hold is not incorrect or misleading as to any matter of fact.
It's not unlikely that some, if not many, of the users of the website will ``exaggerate'' (or just make up) positive aspects of their life after university, their salary, etc.
There also doesn't seem to be any protocol to verify that the users are who they say they are, so anyone could be uploading the personal data, fictitious or otherwise, of anyone else, and this data could be viewed by anyone in the world, so long as they claimed to be an alumni of a particular course.
This is a problem for the company, as they have the responsibility to ensure that the data is accurate, although this may be considered to be something that the company cannot reasonably be expected to regulate / control.
\newline\newline
The company does not seem to comply with the principle of \textbf{Storage Limitation} at all.
There is no mention of data retention period, or how the users might be able to learn their data retention periods.
\newline\newline
Similarly, the company doesn't seem to comply with \textbf{Accountability \& Governance} at all either.
There is no attempt to provide an assurance of GDPR compliance, or to explain why the data is held, when it will be deleted, and who may gain access to it.
\newline\newline
There is no mention of any attempt to comply with \textbf{Integrity \& Confidentiality} either.
There is no mention of any security measure such as encryption, nor do they mention any other technical measures that they might use to process the data securely.
\bigskip
\section{References}
\begin{enumerate}
\item Schukat, M. (2022-09-09). \textit{CT255 Lecture Slides - GDPR.} Blackboard.
\item Wolford, B. \textit{What is GDPR, the EU's new data protection law?} Proton. https://gdpr.eu/what-is-gdpr/
\item Sivula, A. \textit{GDPR: What Happens If You Don't Comply}. AMD Solicitors. https://amdsolicitors.com/gdpr-what-happens-if-you-dont-comply/
\item Rossow, A. \textit{The Birth of GDPR: What Is It And What You Need To Know}. Forbes\\ https://www.forbes.com/sites/andrewrossow/2018/05/25/the-birth-of-gdpr-what-is-it-and-what-you-need-to-know/?sh=62b80a5a55e5
\end{enumerate}
%------------------------------------------------
\end{document}

View File

@ -0,0 +1,97 @@
//package ct255;
import java.util.Random;
public class CT255_HashFunction1 {
public static void main(String[] args) {
int res = 0;
if (args != null && args.length > 0) { // Check for <input> value
res = hashF1(args[0]); // call hash function with <input>
if (res < 0) { // Error
System.out.println("Error: <input> must be 1 to 64 characters long.");
}
else {
System.out.println("input = " + args[0] + " : Hash = " + res);
System.out.println("Start searching for collisions");
int collisionCount = 0; // variable to count the number of collisions found
// string containing all possible ASCII characters (exclusding control characters such as [NULL])
String allChars = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
for (int i = 0; i < 100000; i++) { // checking one million randomly generated strings for hash collisions
StringBuilder str = new StringBuilder(); // creating a new StringBuilder to build char by char
// generating 64 random characters & appending them to str
for (int j = 0; j < 64; j++) {
char c = allChars.charAt(new Random().nextInt(allChars.length())); // selecting a random character from allChars
str.append(c); // appending the randomly selected character to str
}
// hashing str & checking if the hash matches res
if (hashF1(str.toString()) == res) {
collisionCount++; // iterating collisionCount if collision found
System.out.println(str); // printing the String that generated the collision
}
}
// printing the number of collisions found
System.out.printf("%d hash collisions found!", collisionCount);
}
}
else { // No <input>
System.out.println("Use: CT255_HashFunction1 <Input>");
}
}
private static int hashF1(String s){
int ret = -1, i;
int[] hashA = new int[]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; // i extended this array by 6 indices to make code more robust
// essentially, the extent of my improvements was just increasing the size of the hashA array
String filler, sIn;
filler = new String("ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH");
if ((s.length() > 64) || (s.length() < 1)) { // String does not have required length
ret = -1;
}
else {
sIn = s + filler; // Add characters, now have "<input>HABCDEF..."
sIn = sIn.substring(0, 64); // // Limit string to first 64 characters
// System.out.println(sIn); // FYI
for (i = 0; i < sIn.length(); i++){
char byPos = sIn.charAt(i); // get ith character
hashA[0] += (byPos * 17); // Note: A += B means A = A + B
hashA[1] += (byPos * 31);
hashA[2] += (byPos * 101);
hashA[3] += (byPos * 79);
hashA[4] += byPos * 83;
hashA[5] += byPos * 89;
hashA[6] += byPos * 103;
hashA[7] += byPos * 107;
hashA[8] += byPos * 109;
hashA[9] += byPos * 113;
}
hashA[0] %= 255; // % is the modulus operation, i.e. division with rest
hashA[1] %= 255;
hashA[2] %= 255;
hashA[3] %= 255;
hashA[4] %= 255;
hashA[5] %= 255;
hashA[6] %= 255;
hashA[7] %= 255;
hashA[8] %= 255;
hashA[9] %= 255;
ret = hashA[0] + (hashA[1] * 256) + (hashA[2] * 256 * 256) + (hashA[3] * 256 * 256 * 256) + (hashA[4] * 256*256*256*256) + (hashA[5] * 256*256*256*256*256) + (hashA[6] * 256*236*256*256*256*256)
+ (hashA[6] * 256*256*256*256*256*256) + (hashA[7] * 256*256*256*256*256*256*256) + (hashA[8] * 256*256*256*256*256*256*256*256) + (hashA[9] * 256*256*256*256*256*256*256*256*256);
if (ret < 0) ret *= -1;
}
return ret;
}
}

View File

@ -0,0 +1,97 @@
//package ct255;
import java.util.Random;
public class CT255_HashFunction1 {
public static void main(String[] args) {
int res = 0;
if (args != null && args.length > 0) { // Check for <input> value
res = hashF1(args[0]); // call hash function with <input>
if (res < 0) { // Error
System.out.println("Error: <input> must be 1 to 64 characters long.");
}
else {
System.out.println("input = " + args[0] + " : Hash = " + res);
System.out.println("Start searching for collisions");
int collisionCount = 0; // variable to count the number of collisions found
// string containing all possible ASCII characters (exclusding control characters such as [NULL])
String allChars = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
for (int i = 0; i < 100000; i++) { // checking one million randomly generated strings for hash collisions
StringBuilder str = new StringBuilder(); // creating a new StringBuilder to build char by char
// generating 64 random characters & appending them to str
for (int j = 0; j < 64; j++) {
char c = allChars.charAt(new Random().nextInt(allChars.length())); // selecting a random character from allChars
str.append(c); // appending the randomly selected character to str
}
// hashing str & checking if the hash matches res
if (hashF1(str.toString()) == res) {
collisionCount++; // iterating collisionCount if collision found
System.out.println(str); // printing the String that generated the collision
}
}
// printing the number of collisions found
System.out.printf("%d hash collisions found!", collisionCount);
}
}
else { // No <input>
System.out.println("Use: CT255_HashFunction1 <Input>");
}
}
private static int hashF1(String s){
int ret = -1, i;
int[] hashA = new int[]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; // i extended this array by 6 indices to make code more robust
// essentially, the extent of my improvements was just increasing the size of the hashA array
String filler, sIn;
filler = new String("ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH");
if ((s.length() > 64) || (s.length() < 1)) { // String does not have required length
ret = -1;
}
else {
sIn = s + filler; // Add characters, now have "<input>HABCDEF..."
sIn = sIn.substring(0, 64); // // Limit string to first 64 characters
// System.out.println(sIn); // FYI
for (i = 0; i < sIn.length(); i++){
char byPos = sIn.charAt(i); // get ith character
hashA[0] += (byPos * 17); // Note: A += B means A = A + B
hashA[1] += (byPos * 31);
hashA[2] += (byPos * 101);
hashA[3] += (byPos * 79);
hashA[4] += byPos * 83;
hashA[5] += byPos * 89;
hashA[6] += byPos * 103;
hashA[7] += byPos * 107;
hashA[8] += byPos * 109;
hashA[9] += byPos * 113;
}
hashA[0] %= 255; // % is the modulus operation, i.e. division with rest
hashA[1] %= 255;
hashA[2] %= 255;
hashA[3] %= 255;
hashA[4] %= 255;
hashA[5] %= 255;
hashA[6] %= 255;
hashA[7] %= 255;
hashA[8] %= 255;
hashA[9] %= 255;
ret = hashA[0] + (hashA[1] * 256) + (hashA[2] * 256 * 256) + (hashA[3] * 256 * 256 * 256) + (hashA[4] * 256*256*256*256) + (hashA[5] * 256*256*256*256*256) + (hashA[6] * 256*236*256*256*256*256)
+ (hashA[6] * 256*256*256*256*256*256) + (hashA[7] * 256*256*256*256*256*256*256) + (hashA[8] * 256*256*256*256*256*256*256*256) + (hashA[9] * 256*256*256*256*256*256*256*256*256);
if (ret < 0) ret *= -1;
}
return ret;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View 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>

View 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>

View File

@ -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>

View File

@ -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;
}
}

View File

@ -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

View File

@ -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>

View File

@ -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}

View File

@ -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}
% ===============================================

View File

@ -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

View File

@ -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]{...}

View File

@ -0,0 +1,173 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Pattern;
public class Stegano1
{
public static void main(String[] args) {
// Strings to hold the arguments. mode is either A or E for "Add" or "Extract".
String mode, inputfile, outputfile, bitstring;
Boolean err = false; // Boolean to tell if the arguments were passed correctly or not
if (args.length > 1) { // checking that at least one argument was passed to main
// assigning the mode & inputfile arguments
mode = args[0];
inputfile = args[1];
if (inputfile.equals("")) { // checking that an inputfile was provided (String was not empty)
err = true;
}
else if ((mode.equals("A")) && (args.length > 3)){ // checking if the mode is "Add" & that the number of arguments provided was greater than 3
// assigning the outputfile & bitstring arguments
outputfile = args[2];
bitstring = args[3];
if (outputfile.equals("") || bitstring.equals("")) { // checking that neither the outputfile nor bitstring were empty strings
err = true;
}
else {
// hiding the bitstring
hide(inputfile, outputfile, bitstring);
}
}
else if (mode.equals("E")){ // checking if the mode is "Extract"
// retrieving (extracting) the bitstring from text
retrieve(inputfile);
}
else {
err = true;
}
}
else {
err = true;
}
if (err) {
System.out.println();
System.out.println("Use: Stegano1 <A:E><Input File><OutputFile><Bitstring>");
System.out.println("Example to add a bitvector to a file: Stegano1 A inp.txt out.txt 0010101");
System.out.println("Example to extract a bitvector from a file: Stegano1 E inp.txt");
}
}
// method to hide a bitstring in a copy the input file provided
static void hide(String inpFile, String outFile, String bitString) {
// to encode 2 bits with just one symbol, i'm going to represent the binary digits as an analog represenation of the number it represents plus one
// e.g., 00 will be represented as " " (1 space), 01 as " " (2 spaces), 10 as " " (3 spaces), and 11 as " " (4 spaces)
// the two bits are treated as a binary number, and then i add one to said binary number to get the number of spaces that will represent that number
BufferedReader reader; // declaring a BufferedReader for the input file
BufferedWriter writer; // declaring a BufferedWriter for the output file
try {
// initialising the reader & writer to FileReaders of their respective files (inpFile & outFile)
reader = new BufferedReader(new FileReader(inpFile));
writer = new BufferedWriter(new FileWriter(outFile));
String line = reader.readLine(); // reading in the first line from the input file
// checking if the number of bits in the bitstring is uneven, and if so, adding a '0' onto the end
if (bitString.length() % 2 != 0) { bitString = bitString.concat("0"); }
// will loop until there are no more lines to be read in from the input file (inpFile)
while (line != null) {
// if the bitString is not (yet) an empty String
if (!bitString.equals("")) {
// if the first 2-bit substring is 00, adding one space to the end of the line
if (bitString.substring(0,2).equals("00")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 01, adding two spaces to the end of the line
else if (bitString.substring(0,2).equals("01")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 10, adding three spaces to the end of the line
else if (bitString.substring(0,2).equals("10")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 11, adding four spaces to the end of the line
else if (bitString.substring(0,2).equals("11")) {
line = line.concat(" ");
}
// removing the first two bits from the bitString now that they have been used
bitString = bitString.substring(2, bitString.length()); // replacing bitString with it's substring that goes from the third character to the last character
}
// writing the amended line to the output file
writer.write(line);
writer.newLine();
// reading the next line
line = reader.readLine();
}
// closing the reader & the writer
reader.close();
writer.close();
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
// method to retrieve a hidden string from the input file provided
static void retrieve(String inpFile) {
BufferedReader reader; // declaring a BufferedReader for the input file (inpFile)
String message = "";
try {
reader = new BufferedReader(new FileReader(inpFile)); // initialising the reader to a FileReader of the input file (inpFile)
String line = reader.readLine(); // reading in the first line from the input file
// will loop until there are no more lines to be read in from the input file
while (line != null) {
// checking if the line ends in a space using a regular expression
if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by a space followed by the end of a line)
if (Pattern.matches(".* $", line)) { // checking if the line ends in four spaces using a regular expression
message = message.concat("11"); // concatenating "11" onto the end of the message String (four spaces represents "11")
}
else if (Pattern.matches(".* $", line)) { // checking if the line ends in three spaces using a regular expression
message = message.concat("10"); // concatenating "10" onto the end of the message String (three spaces represents "10")
}
else if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by two spaces followed by the end of a line)
message = message.concat("01"); // concatenating a "1" onto the message String (two spaces represent a "1")
}
else { // essentially, this "else" means "if the line ends with one space but not two"
message = message.concat("00"); // concatenating a "0" onto the message String (one space represents a "0")
}
}
else { // if the String does not end in a space, then there is no (more) message to read
break;
}
// reading the next line
line = reader.readLine();
}
// closing in the reader
reader.close();
// checking if the message String is empty so that an error message can be printed if no hidden message was found
if (message.equals("")) {
message = "Error: No hidden message found!";
}
// printing out the message
System.out.println(message);
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -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
%----------------------------------------------------------------------------------------

View File

@ -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="0">
<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="0">
<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>

View File

@ -0,0 +1,383 @@
\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 3\\
\normalsize
Steganography\\
\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.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Pattern;
public class Stegano1
{
public static void main(String[] args) {
// Strings to hold the arguments. mode is either A or E for "Add" or "Extract".
String mode, inputfile, outputfile, bitstring;
Boolean err = false; // Boolean to tell if the arguments were passed correctly or not
if (args.length > 1) { // checking that at least one argument was passed to main
// assigning the mode & inputfile arguments
mode = args[0];
inputfile = args[1];
if (inputfile.equals("")) { // checking that an inputfile was provided (String was not empty)
err = true;
}
else if ((mode.equals("A")) && (args.length > 3)){ // checking if the mode is "Add" & that the number of arguments provided was greater than 3
// assigning the outputfile & bitstring arguments
outputfile = args[2];
bitstring = args[3];
if (outputfile.equals("") || bitstring.equals("")) { // checking that neither the outputfile nor bitstring were empty strings
err = true;
}
else {
// hiding the bitstring
hide(inputfile, outputfile, bitstring);
}
}
else if (mode.equals("E")){ // checking if the mode is "Extract"
// retrieving (extracting) the bitstring from text
retrieve(inputfile);
}
else {
err = true;
}
}
else {
err = true;
}
if (err) {
System.out.println();
System.out.println("Use: Stegano1 <A:E><Input File><OutputFile><Bitstring>");
System.out.println("Example to add a bitvector to a file: Stegano1 A inp.txt out.txt 0010101");
System.out.println("Example to extract a bitvector from a file: Stegano1 E inp.txt");
}
}
// method to hide a bitstring in a copy the input file provided
static void hide(String inpFile, String outFile, String bitString) {
BufferedReader reader; // declaring a BufferedReader for the input file
BufferedWriter writer; // declaring a BufferedWriter for the output file
try {
// initialising the reader & writer to FileReaders of their respective files (inpFile & outFile)
reader = new BufferedReader(new FileReader(inpFile));
writer = new BufferedWriter(new FileWriter(outFile));
String line = reader.readLine(); // reading in the first line from the input file
// will loop until there are no more lines to be read in from the input file (inpFile)
while (line != null) {
// if the bitString is not (yet) an empty String
if (!bitString.equals("")) {
// if the first bit (char) of the bitString is 0
if (bitString.charAt(0) == '0') { // note: must use '' instead of "" for char literals
line = line.concat(" "); // concatenating a space to the end of the line (one space represents a 0)
}
// if the first bit of the bitString is 1
if (bitString.charAt(0) == '1') {
line = line.concat(" "); // concatenating two spaces to the end of the line (two spaces represents a 1)
}
// removing the first bit from the bitString now that it has been used
bitString = bitString.substring(1, bitString.length()); // replacing bitString with it's substring that goes from the second character to the last character
}
// writing the amended line to the output file
writer.write(line);
writer.newLine();
// reading the next line
line = reader.readLine();
}
// closing the reader & the writer
reader.close();
writer.close();
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
// method to retrieve a hidden string from the input file provided
static void retrieve(String inpFile) {
BufferedReader reader; // declaring a BufferedReader for the input file (inpFile)
String message = "";
try {
reader = new BufferedReader(new FileReader(inpFile)); // initialising the reader to a FileReader of the input file (inpFile)
String line = reader.readLine(); // reading in the first line from the input file
// will loop until there are no more lines to be read in from the input file
while (line != null) {
// checking if the line ends in a space using a regular expression
if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by a space followed by the end of a line)
// checking if the line ends in two spaces using a regular expression
if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by two spaces followed by the end of a line)
message = message.concat("1"); // concatenating a "1" onto the message String (two spaces represent a "1")
}
else { // essentially, this "else" means "if the line ends with one space but not two"
message = message.concat("0"); // concatenating a "0" onto the message String (one space represents a "0")
}
}
else { // if the String does not end in a space, then there is no (more) message to read
break;
}
// reading the next line
line = reader.readLine();
}
// closing in the reader
reader.close();
// checking if the message String is empty so that an error message can be printed if no hidden message was found
if (message.equals("")) {
message = "Error: No hidden message found!";
}
// printing out the message
System.out.println(message);
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
}
\end{lstlisting}
\subsection{Screenshot of Compilation \& Output}
\includegraphics[width = 15cm]{output1.png}
\bigskip
%------------------------------------------------
\section{Problem 2}
\subsection{Code}
\begin{lstlisting}[language=java]
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Pattern;
public class Stegano1
{
public static void main(String[] args) {
// Strings to hold the arguments. mode is either A or E for "Add" or "Extract".
String mode, inputfile, outputfile, bitstring;
Boolean err = false; // Boolean to tell if the arguments were passed correctly or not
if (args.length > 1) { // checking that at least one argument was passed to main
// assigning the mode & inputfile arguments
mode = args[0];
inputfile = args[1];
if (inputfile.equals("")) { // checking that an inputfile was provided (String was not empty)
err = true;
}
else if ((mode.equals("A")) && (args.length > 3)){ // checking if the mode is "Add" & that the number of arguments provided was greater than 3
// assigning the outputfile & bitstring arguments
outputfile = args[2];
bitstring = args[3];
if (outputfile.equals("") || bitstring.equals("")) { // checking that neither the outputfile nor bitstring were empty strings
err = true;
}
else {
// hiding the bitstring
hide(inputfile, outputfile, bitstring);
}
}
else if (mode.equals("E")){ // checking if the mode is "Extract"
// retrieving (extracting) the bitstring from text
retrieve(inputfile);
}
else {
err = true;
}
}
else {
err = true;
}
if (err) {
System.out.println();
System.out.println("Use: Stegano1 <A:E><Input File><OutputFile><Bitstring>");
System.out.println("Example to add a bitvector to a file: Stegano1 A inp.txt out.txt 0010101");
System.out.println("Example to extract a bitvector from a file: Stegano1 E inp.txt");
}
}
// method to hide a bitstring in a copy the input file provided
static void hide(String inpFile, String outFile, String bitString) {
// to encode 2 bits with just one symbol, i'm going to represent the binary digits as an analog represenation of the number it represents plus one
// e.g., 00 will be represented as " " (1 space), 01 as " " (2 spaces), 10 as " " (3 spaces), and 11 as " " (4 spaces)
// the two bits are treated as a binary number, and then i add one to said binary number to get the number of spaces that will represent that number
BufferedReader reader; // declaring a BufferedReader for the input file
BufferedWriter writer; // declaring a BufferedWriter for the output file
try {
// initialising the reader & writer to FileReaders of their respective files (inpFile & outFile)
reader = new BufferedReader(new FileReader(inpFile));
writer = new BufferedWriter(new FileWriter(outFile));
String line = reader.readLine(); // reading in the first line from the input file
// checking if the number of bits in the bitstring is uneven, and if so, adding a '0' onto the end
if (bitString.length() % 2 != 0) { bitString = bitString.concat("0"); }
// will loop until there are no more lines to be read in from the input file (inpFile)
while (line != null) {
// if the bitString is not (yet) an empty String
if (!bitString.equals("")) {
// if the first 2-bit substring is 00, adding one space to the end of the line
if (bitString.substring(0,2).equals("00")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 01, adding two spaces to the end of the line
else if (bitString.substring(0,2).equals("01")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 10, adding three spaces to the end of the line
else if (bitString.substring(0,2).equals("10")) {
line = line.concat(" ");
}
// if the first 2-bit substring is 11, adding four spaces to the end of the line
else if (bitString.substring(0,2).equals("11")) {
line = line.concat(" ");
}
// removing the first two bits from the bitString now that they have been used
bitString = bitString.substring(2, bitString.length()); // replacing bitString with it's substring that goes from the third character to the last character
}
// writing the amended line to the output file
writer.write(line);
writer.newLine();
// reading the next line
line = reader.readLine();
}
// closing the reader & the writer
reader.close();
writer.close();
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
// method to retrieve a hidden string from the input file provided
static void retrieve(String inpFile) {
BufferedReader reader; // declaring a BufferedReader for the input file (inpFile)
String message = "";
try {
reader = new BufferedReader(new FileReader(inpFile)); // initialising the reader to a FileReader of the input file (inpFile)
String line = reader.readLine(); // reading in the first line from the input file
// will loop until there are no more lines to be read in from the input file
while (line != null) {
// checking if the line ends in a space using a regular expression
if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by a space followed by the end of a line)
if (Pattern.matches(".* $", line)) { // checking if the line ends in four spaces using a regular expression
message = message.concat("11"); // concatenating "11" onto the end of the message String (four spaces represents "11")
}
else if (Pattern.matches(".* $", line)) { // checking if the line ends in three spaces using a regular expression
message = message.concat("10"); // concatenating "10" onto the end of the message String (three spaces represents "10")
}
else if (Pattern.matches(".* $", line)) { // (checking if the String line contains any amount of any characters, followed by two spaces followed by the end of a line)
message = message.concat("01"); // concatenating a "1" onto the message String (two spaces represent a "1")
}
else { // essentially, this "else" means "if the line ends with one space but not two"
message = message.concat("00"); // concatenating a "0" onto the message String (one space represents a "0")
}
}
else { // if the String does not end in a space, then there is no (more) message to read
break;
}
// reading the next line
line = reader.readLine();
}
// closing in the reader
reader.close();
// checking if the message String is empty so that an error message can be printed if no hidden message was found
if (message.equals("")) {
message = "Error: No hidden message found!";
}
// printing out the message
System.out.println(message);
}
// catching any IOExceptions
catch (IOException e) {
e.printStackTrace();
}
}
}
\end{lstlisting}
\subsection{Output}
\includegraphics[width = 15cm]{output2.png}
\end{document}

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -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}
% ===============================================

View File

@ -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

View File

@ -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]{...}

View File

@ -0,0 +1,116 @@
/**
* CT255 - Assignment 3
* Skeleton code for Steganography assignment.
*
* @author Michael Schukat
* @version 1.0
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Stegano1
{
/**
* Constructor for objects of class Stegano1
*/
public Stegano1()
{
}
public static void main(String[] args) {
String arg1, arg2, arg3, arg4;
Boolean err = false;
if (args != null && args.length > 1) { // Check for minimum number of arguments
arg1 = args[0];
arg2 = args[1];
if (arg2 == "") {
err = true;
}
else if ((arg1 == "A") && (args.length > 3)){
// Get other arguments
arg3 = args[2];
arg4 = args[3];
if (arg3 == "" || arg4 == "") {
err = true;
}
else {
// Hide bitstring
hide(arg2, arg3, arg4);
}
}
else if (arg1 == "E"){
// Extract bitstring from text
retrieve(arg2);
}
else {
err = true;
}
}
else {
err = true;
}
if (err == true) {
System.out.println();
System.out.println("Use: Stegano1 <A:E><Input File><OutputFile><Bitstring>");
System.out.println("Example: Stegano1 A inp.txt out.txt 0010101");
System.out.println("Example: Stegano1 E inp.txt");
}
}
static void hide(String inpFile, String outFile, String binString) {
//
BufferedReader reader;
BufferedWriter writer;
try {
reader = new BufferedReader(new FileReader(inpFile));
writer = new BufferedWriter(new FileWriter(outFile));
String line = reader.readLine();
while (line != null) {
// Your code starts here
// Store amended line in output file
writer.write(line);
writer.newLine();
// read next line
line = reader.readLine();
}
reader.close();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
static void retrieve(String inpFile) {
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(inpFile));
String line = reader.readLine();
while (line != null) {
// Your code starts here
// System.out.println(line);
// read next line
line = reader.readLine();
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,57 @@
The Stolen Child
Where dips the rocky highland
Of Sleuth Wood in the lake,
There lies a leafy island
Where flapping herons wake
The drowsy water rats;
There we've hid our faery vats,
Full of berrys
And of reddest stolen cherries.
Come away, O human child!
To the waters and the wild
With a faery, hand in hand,
For the world's more full of weeping than you can understand.
Where the wave of moonlight glosses
The dim gray sands with light,
Far off by furthest Rosses
We foot it all the night,
Weaving olden dances
Mingling hands and mingling glances
Till the moon has taken flight;
To and fro we leap
And chase the frothy bubbles,
While the world is full of troubles
And anxious in its sleep.
Come away, O human child!
To the waters and the wild
With a faery, hand in hand,
For the world's more full of weeping than you can understand.
Where the wandering water gushes
From the hills above Glen-Car,
In pools among the rushes
That scarce could bathe a star,
We seek for slumbering trout
And whispering in their ears
Give them unquiet dreams;
Leaning softly out
From ferns that drop their tears
Over the young streams.
Come away, O human child!
To the waters and the wild
With a faery, hand in hand,
For the world's more full of weeping than you can understand.
Away with us he's going,
The solemn-eyed:
He'll hear no more the lowing
Of the calves on the warm hillside
Or the kettle on the hob
Sing peace into his breast,
Or see the brown mice bob
Round and round the oatmeal chest.
For he comes, the human child,
To the waters and the wild
With a faery, hand in hand,
For the world's more full of weeping than he can understand.

View File

@ -0,0 +1,57 @@
The Stolen Child
Where dips the rocky highland
Of Sleuth Wood in the lake,
There lies a leafy island
Where flapping herons wake
The drowsy water rats;
There we've hid our faery vats,
Full of berrys
And of reddest stolen cherries.
Come away, O human child!
To the waters and the wild
With a faery, hand in hand,
For the world's more full of weeping than you can understand.
Where the wave of moonlight glosses
The dim gray sands with light,
Far off by furthest Rosses
We foot it all the night,
Weaving olden dances
Mingling hands and mingling glances
Till the moon has taken flight;
To and fro we leap
And chase the frothy bubbles,
While the world is full of troubles
And anxious in its sleep.
Come away, O human child!
To the waters and the wild
With a faery, hand in hand,
For the world's more full of weeping than you can understand.
Where the wandering water gushes
From the hills above Glen-Car,
In pools among the rushes
That scarce could bathe a star,
We seek for slumbering trout
And whispering in their ears
Give them unquiet dreams;
Leaning softly out
From ferns that drop their tears
Over the young streams.
Come away, O human child!
To the waters and the wild
With a faery, hand in hand,
For the world's more full of weeping than you can understand.
Away with us he's going,
The solemn-eyed:
He'll hear no more the lowing
Of the calves on the warm hillside
Or the kettle on the hob
Sing peace into his breast,
Or see the brown mice bob
Round and round the oatmeal chest.
For he comes, the human child,
To the waters and the wild
With a faery, hand in hand,
For the world's more full of weeping than he can understand.

View File

@ -0,0 +1,91 @@
import java.util.ArrayList;
public class DiffieHellman {
public static void main(String[] args) {
generate_params();
}
// method to generate the random DH parameters
public static void generate_params() {
int prime = generate_prime(); // generating a prime number
System.out.println("prime: " + prime);
int primitive_root = generate_primitive_root(prime); // generating a primitive root of that prime
System.out.println("prime: " + prime + ". primtive root : " + primitive_root);
}
// method to generate a prime number in the range 10000 - 100000
public static int generate_prime() {
// generating an ArrayList of prime numbers in the range 10,000 to 100,000 using the Sieve of Eratosthenes
// creating a list of consecutive integers from 2 through 100,000
ArrayList<Integer> integers = new ArrayList<Integer>();
for (int n = 2; n <= 100000; n++) {
integers.add(n);
}
// initially, let p equal 2, the smallest prime number in the list.
int p = integers.get(0);
// variable to hold the number of known primes in the ArrayList
int primes_count = 1;
// looping while p is less than the final value in the list
while (p < integers.get(integers.size() - 1)) {
// removing the mutliples of p from the list
for (int i = 2; (i * p) <= integers.get(integers.size() - 1); i++) {
integers.remove(Integer.valueOf(i * p));
}
// let p equal the new smallest element in the ArrayList
p = integers.get(primes_count++);
}
// cutting out the section of the ArrayList that contains prime number outside the appropriate range
while (integers.get(0) < 10000) { // removing the first element of the ArrayList while the first index of the ArrayList holds a value less than 10,000
integers.remove(0);
}
// selecting the element at a random index in the ArrayList of primes as our prime number
int prime = integers.get((int) (Math.random() * (integers.size() - 1)));
return prime;
}
public static int generate_primitive_root(int prime) {
// ArrayList<Integer> primitive_roots = new ArrayList<Integer>(); // ArrayList to hold the primitive roots found
// looping through all the numbers in the range 2 to the prime minus 1 to see if they're primitive roots of the prime, breaking when we find the first primitive root
for (int n = 3; n < prime - 1; n++) {
boolean is_n_a_primtive_root = true; // boolean to tell whether or not n is a primtive root
ArrayList<Integer> distinct_values = new ArrayList<Integer>(); // ArrayList to hold the distinct values of a candidate primitive root modulo the prime
// loop to check if n is a primitive root by raising it to the power of x modulo the prime
for (int x = 2; x < prime - 2; x++) {
// setting is_n_a_primtive_root to false and breaking out of the loop if n to the power of x modulo the prime is already in the distinct_values ArrayList
if (distinct_values.contains((n^x) % prime)) {
is_n_a_primtive_root = false;
System.out.println(n + " is not a primitive root");
break;
}
else {
distinct_values.add((n^x) % prime);
}
}
// adding n to the list of primitive roots if it is a primitive root of the prime passed to the function
if (is_n_a_primtive_root) {
// primitive_roots.add(n);
return n;
}
}
// selecting a random value in the list of primitive roots to be our primtitive root
// int random_primitive_root = primitive_roots.get((int) (Math.random() * (primitive_roots.size() - 1)));
// int random_primitive_root = -1;
// return random_primitive_root;
//
// returning -1 if no primitive root found
return -1;
}
}

Binary file not shown.

Binary file not shown.