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

Run dos2unix to have homogeneous endlines #133

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
template: |
## What’s Changed
template: |
## What’s Changed

$CHANGES
40 changes: 20 additions & 20 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# .github/workflows/tests.yml
name: Tests
on: pull_request
jobs:
tests:
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: pip install nox==2019.11.9
- run: pip install poetry==1.0.5
- run: nox
# .github/workflows/tests.yml
name: Tests
on: pull_request
jobs:
tests:
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: pip install nox==2019.11.9
- run: pip install poetry==1.0.5
- run: nox
86 changes: 43 additions & 43 deletions name_that_hash/HashTypeObj.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
class HashType:
"""
Every hash given to our program will be associated with one object.
This object contains the possible type of hash
and provides ways to print that hash.
"""
def __init__(self, chash: str, nth, hash_info, kwargs):
self.chash = chash
self.nth = nth
self.popular = hash_info.popular
# prototypes is given as a generator
if "extreme" in kwargs and kwargs["extreme"]:
self.prototypes = nth.identify_all(chash)
else:
self.prototypes = nth.identify(chash)
self.prototypes = self.sort_by_popular()
self.hash_obj = {self.chash: self.prototypes}
def get_prototypes(self):
return self.prototypes
def sort_by_popular(self):
"""
Sorts the list by popular + everything else.
We do this using the self.popular set. Sets have O(1) lookup, so it's cheap.
If one named_tuple is in the popular set, we add it to the populars list and remove it from prototypes.
We then return populars list + prototypes.
"""
to_ret = []
populars = []
for i in self.prototypes:
if i.name in self.popular:
populars.append(i.__dict__)
else:
to_ret.append(i.__dict__)
return populars + to_ret
class HashType:
"""
Every hash given to our program will be associated with one object.
This object contains the possible type of hash
and provides ways to print that hash.
"""

def __init__(self, chash: str, nth, hash_info, kwargs):
self.chash = chash
self.nth = nth

self.popular = hash_info.popular

# prototypes is given as a generator
if "extreme" in kwargs and kwargs["extreme"]:
self.prototypes = nth.identify_all(chash)
else:
self.prototypes = nth.identify(chash)
self.prototypes = self.sort_by_popular()

self.hash_obj = {self.chash: self.prototypes}

def get_prototypes(self):
return self.prototypes

def sort_by_popular(self):
"""
Sorts the list by popular + everything else.

We do this using the self.popular set. Sets have O(1) lookup, so it's cheap.
If one named_tuple is in the popular set, we add it to the populars list and remove it from prototypes.

We then return populars list + prototypes.
"""

to_ret = []
populars = []
for i in self.prototypes:
if i.name in self.popular:
populars.append(i.__dict__)
else:
to_ret.append(i.__dict__)
return populars + to_ret
76 changes: 38 additions & 38 deletions name_that_hash/check_hashes.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import base64
import logging
from name_that_hash import HashTypeObj, hash_info
class HashChecker:
"""
Call this with an input to identify hashes
"""
def __init__(self, kwargs, nth):
self.kwargs = kwargs
self.hashinfo_obj = hash_info.HashInformation()
self.nth = nth
self.output = []
def file_input(self, f):
for nr, line in enumerate(f, start=1):
line = str(line).strip()
if not line:
logging.debug(f"Skipped empty line {nr}")
continue
self.single_hash(line)
logging.debug(f"{self.output}")
def single_hash(self, chash: str):
if "base64" in self.kwargs and self.kwargs["base64"]:
logging.debug("decoding as base64")
try:
# b64decode returns Bytes obj
chash = base64.b64decode(chash).decode("utf-8")
except:
logging.debug("Failed to base64 decode")
self.output.append(
HashTypeObj.HashType(chash, self.nth, self.hashinfo_obj, self.kwargs)
)
import base64
import logging

from name_that_hash import HashTypeObj, hash_info


class HashChecker:
"""
Call this with an input to identify hashes
"""

def __init__(self, kwargs, nth):
self.kwargs = kwargs
self.hashinfo_obj = hash_info.HashInformation()
self.nth = nth
self.output = []

def file_input(self, f):
for nr, line in enumerate(f, start=1):
line = str(line).strip()
if not line:
logging.debug(f"Skipped empty line {nr}")
continue
self.single_hash(line)
logging.debug(f"{self.output}")

def single_hash(self, chash: str):
if "base64" in self.kwargs and self.kwargs["base64"]:
logging.debug("decoding as base64")

try:
# b64decode returns Bytes obj
chash = base64.b64decode(chash).decode("utf-8")
except:
logging.debug("Failed to base64 decode")
self.output.append(
HashTypeObj.HashType(chash, self.nth, self.hashinfo_obj, self.kwargs)
)
42 changes: 21 additions & 21 deletions name_that_hash/hash_info.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
class HashInformation:
def __init__(self):
self.popular = set(
[
"MD5",
"MD4",
"NTLM",
"SHA-256",
"SHA-512",
"Keccak-256",
"Keccak-512",
"Blake2",
"bcrypt",
"SHA-1",
"HMAC-SHA1 (key = $salt)",
"CryptoCurrency(PrivateKey)",
"SHA-338",
"Domain Cached Credentials",
"Domain Cached Credentials 2",
]
)
class HashInformation:
def __init__(self):
self.popular = set(
[
"MD5",
"MD4",
"NTLM",
"SHA-256",
"SHA-512",
"Keccak-256",
"Keccak-512",
"Blake2",
"bcrypt",
"SHA-1",
"HMAC-SHA1 (key = $salt)",
"CryptoCurrency(PrivateKey)",
"SHA-338",
"Domain Cached Credentials",
"Domain Cached Credentials 2",
]
)
Loading