Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

James Christie PR #2

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cf4e3a3
Finished python version
jmattspartacus Dec 13, 2021
2502656
Added usage for python script
jmattspartacus Dec 13, 2021
4ab4361
Cleanup and comments on python
jmattspartacus Dec 13, 2021
d4d48be
Finished C# version
jmattspartacus Dec 14, 2021
03e2066
Added info to data directory
jmattspartacus Dec 14, 2021
881f2b6
Added incomplete rust version and updated usage
jmattspartacus Dec 14, 2021
b4bad78
Merge branch 'trholmes:main' into main
jmattspartacus Dec 14, 2021
23f04af
Day 2 python done
jmattspartacus Dec 14, 2021
32c5aa1
Added dependency list to python day2
jmattspartacus Dec 14, 2021
fc71064
Added axis labels
jmattspartacus Dec 14, 2021
e717b7c
Finaly fixed cpp version for day 1
jmattspartacus Dec 15, 2021
2161ee6
added usage for day_1 cpp
jmattspartacus Dec 15, 2021
d713a4b
Added notes on performance
jmattspartacus Dec 15, 2021
4743115
updated gitignore
jmattspartacus Dec 15, 2021
aaa8eb1
removed data file that didn't need to get comitted
jmattspartacus Dec 15, 2021
937787f
Made all the Day1 things put stuff in the data dir
jmattspartacus Dec 15, 2021
9d90702
removed rust for day2, not going to work
jmattspartacus Dec 15, 2021
e433009
Merge branch 'trholmes:main' into main
jmattspartacus Dec 15, 2021
4ce2fb2
Julia working!
jmattspartacus Dec 15, 2021
5cdac76
Merge branch 'main' of https://github.com/jmattspartacus/YETI2021 int…
jmattspartacus Dec 15, 2021
4c1539b
day3 done with python
jmattspartacus Dec 15, 2021
fd220c0
day3 rust version
jmattspartacus Dec 15, 2021
54f1216
Removed html results from day1
jmattspartacus Dec 15, 2021
416f872
Added html to git ignore
jmattspartacus Dec 15, 2021
ce3aba3
Merge branch 'trholmes:main' into main
jmattspartacus Dec 16, 2021
44d5780
Fixed day 2, it's a map now
jmattspartacus Dec 16, 2021
cb09b97
Day4 done, I think
jmattspartacus Dec 16, 2021
dabb1cb
Day 4 in rust
jmattspartacus Dec 17, 2021
f92a542
Merge branch 'trholmes:main' into main
jmattspartacus Dec 17, 2021
7ce30f9
Finished day5 in python!
jmattspartacus Dec 17, 2021
242577f
Cleanup python, finished the rust version of day5
jmattspartacus Dec 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Day_1/C++/**.o
Day_1/C++/**.txt
**/C#/bin/**
**/C#/obj/**
**/rust/target/**
Day_2/rust/**
**.html
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files.associations": {
"unordered_map": "cpp",
"ostream": "cpp",
"iosfwd": "cpp"
},
"python.pythonPath": "/usr/bin/python3"
}
9 changes: 9 additions & 0 deletions Day_1/C#/C#comphash.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>C_comphash</RootNamespace>
</PropertyGroup>

</Project>
80 changes: 80 additions & 0 deletions Day_1/C#/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Net;
using System.Text.RegularExpressions;

namespace C_comphash
{
class Program {
const string charpool = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const int pwd_length = 4;
class strgen {
int[] state;
public strgen(){
state = new int[pwd_length];
}
public string next() {
string ret = "";
for(int i = 0; i < pwd_length; i++) {
ret += charpool[state[i] % 62];
}
for(int i = 0; i < pwd_length; i++){
if (state[i] < 62) {
state[i] += 1;
break;
} else {
state[i] = 0;
}
}
return ret;
}
}
static void Main(string[] args) {
// get the target hash from file
string target_hash = System.IO.File.ReadAllText("../data/targethash.txt");
Console.WriteLine(target_hash);

// use this to generate possible strings
strgen generator = new strgen();
string t_string;

// hashing object
var MD5 = System.Security.Cryptography.MD5.Create();

System.Text.StringBuilder sb = new System.Text.StringBuilder();
byte[] t_bytes;
byte[] hashed;
// now compute hashes and test
while(true){
t_string = generator.next();
t_bytes = System.Text.Encoding.ASCII.GetBytes(t_string);
hashed = MD5.ComputeHash(t_bytes);

// convert the hashed bytes into a string
// splits the bytes into low and high nibbles
for (int i = 0; i < hashed.Length; i++) {
sb.Append(hashed[i].ToString("x2"));
}
if (sb.ToString().Equals(target_hash)) {
break;
}
sb.Clear();
}

// echo what we found
Console.WriteLine($"String with the given hash {target_hash} is {t_string}");
// download the final url
WebClient client = new WebClient();
string htmlstring = client.DownloadString($"https://tiny.utk.edu/{t_string}");
System.IO.File.WriteAllText("../data/page.html", htmlstring);

// we know it's a gist based on the HTML we got, let's get the raw address
Regex regex = new Regex("href=\"(.+raw.+?)\"", RegexOptions.Compiled | RegexOptions.IgnoreCase);
string matchstr = "";
foreach(Match match in regex.Matches(htmlstring))
{
matchstr += match.Groups[1].Value;
}
client.DownloadFile($"https://gist.github.com/{matchstr}", "../data/FourVectorTest.csv");
}
}
}
6 changes: 6 additions & 0 deletions Day_1/C#/Usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To use this, you'll need .net version > 2 installed. Once that is done, cd into the C# directory and do
```
dotnet build
dotnet run
```
if this doesn't work, I've borked something with the upload.
1 change: 1 addition & 0 deletions Day_1/C++/clangbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clang++ -l ssl -l crypto comphash.cpp -O3 -v -o comphash.o 2> builderr.txt
83 changes: 83 additions & 0 deletions Day_1/C++/comphash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <openssl/md5.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <map>
#include <sstream>
#include <boost/format.hpp>

// how long is the hashed value?
const int pwd_length = 4;

// pool of characters for making guesses
const char *charpool = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

struct strgen
{
int state[pwd_length];
strgen(){
for(int i = 0; i < pwd_length; i++) {
state[i] = 0;
}
};

std::string next() {
std::string ret = "";
for(int i = 0; i < pwd_length; i++) {
ret += charpool[state[i] % 62];
}
for(int i = 0; i < pwd_length; i++){
if (state[i] < 61) {
state[i] += 1;
break;
} else {
state[i] = 0;
}
}
return ret;
};
};

int main(void) {
std::string targetstr;
// get the target hash from the file
{
std::ifstream ifs("../data/targethash.txt");
targetstr.assign( (std::istreambuf_iterator<char>(ifs) ),
(std::istreambuf_iterator<char>() ) );
ifs.close();
}

// generator for combinations
strgen generator = strgen();
std::string t_str = generator.next();
std::string first;
for(int i = 0; i < pwd_length; i++){
first.push_back(t_str[i]);
}
unsigned char hash[MD5_DIGEST_LENGTH];
while(true){
MD5((unsigned char *)t_str.c_str(), pwd_length, hash);
// this lovely mess can be blamed on my compiler not recognizing std::format()
std::string hashstr = (boost::format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x")%
(int)hash[0]%(int)hash[1]%(int)hash[2]%(int)hash[3]%
(int)hash[4]%(int)hash[5]%(int)hash[6]%(int)hash[7]%
(int)hash[8]%(int)hash[9]%(int)hash[10]%(int)hash[11]%
(int)hash[12]%(int)hash[13]%(int)hash[14]%(int)hash[15]).str();
//std::cout << hashstr << std::endl;
if (hashstr.compare(targetstr) == 0) {
break;
}
// do after the loop body so that we can store it before the initial loop
t_str = generator.next();
// a little bit of insurance to prevent infinite loops
// could probably store this on the generator though
if (t_str.compare(first) == 0) {
std::cout << "failed to find hash" << std::endl;
return -1;
}
}

std::cout << "The string with the hash " << targetstr << " is " << t_str << std::endl;

}
8 changes: 8 additions & 0 deletions Day_1/C++/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
To use this, from a terminal (bash, zsh, etc) do
```sh
source clangbuild.sh
```

Dependencies:
boost (tested with 1.71)
openssl (tested with 1.1.1f)
Loading