Skip to content

Instantly share code, notes, and snippets.

def decrypt_and_compare(data, key, iv, expected):
unpad = lambda s: s[0:-ord(s[-1])]
aes = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CBC, iv)
# Decrypt each block of data, except for the last one
for i in xrange(0, len(data) - 16, 16):
if aes.decrypt(data[i:i+16]) != expected[i:i+16]:
return False
# Decrypt the last block of data, unpad, and compare
@rgov
rgov / decipherit.c
Last active June 19, 2022 10:52
Dictionary attack on encipher.it ciphertexts
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <CommonCrypto/CommonCryptor.h>
#include <CommonCrypto/CommonHMAC.h>
#include <CommonCrypto/CommonKeyDerivation.h>
#include <dispatch/dispatch.h>
# for http://www.reddit.com/r/codes/comments/3874s7/crack_this_old_code_for_shiny_gold/
# this is from source to InfoLock 5.5, http://sourceforge.net/projects/infolock
encoder_ring = {
'a': 8, 'b': 2, 'c': 3, 'd': 4, 'e': 7, 'f': 19, 'g': 5, 'h': 1, 'i': 9,
'j': 10, 'k': 29, 'l': 12, 'm': 24, 'n': 14, 'o': 15, 'p': 16, 'q': 25,
'r': 18, 's': 6, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 13, 'y': 17,
'z': 26, '!': 11, '?': 30, 'A': 31, 'B': 32, 'C': 33, 'D': 34, 'E': 35,
'F': 36, 'G': 37, 'H': 38, 'I': 39, 'J': 40, 'K': 41, 'L': 42, 'M': 43,
'N': 44, 'O': 45, 'P': 46, 'Q': 47, 'R': 48, 'S': 49, 'T': 50, 'U': 51,
'V': 52, 'W': 53, 'X': 54, 'Y': 55, 'Z': 56, ',': 57, '\'': 58, ':': 59,
diff --git a/Makefile b/Makefile
index ceb9d77..c9bd8fd 100644
--- a/Makefile
+++ b/Makefile
@@ -60,7 +60,7 @@ SOMINOR=1
SORELEASE?=.0# Declare empty to leave out from library file name.
MINISAT_CXXFLAGS = -I. -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -Wall -Wno-parentheses -Wextra
-MINISAT_LDFLAGS = -Wall -lz
+MINISAT_LDFLAGS = -Wall
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 27fd96f..1cc8f01 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -320,14 +320,6 @@ endif()
# -----------------------------------------------------------------------------
# Find Minisat
# -----------------------------------------------------------------------------
-find_package(minisat)
-set(MINISAT_INCLUDE_DIRS "" CACHE PATH "MiniSat include directory")
@rgov
rgov / Fix Phone Numbers.scpt
Created February 21, 2016 15:30
Add an explicit US country code prefix to all phone numbers in Contacts
on UnformatPhoneNumber(theNumber)
set digits to {}
if theNumber starts with "+" then
set the end of digits to "+"
end if
repeat with i from 1 to count of theNumber
set theDigit to item i of theNumber
if theDigit is in "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" then
set the end of digits to theDigit
end if
@rgov
rgov / rfc3851.asn
Created February 25, 2016 13:48
ASN.1 Module from RFC 3851
{ iso(1) member-body(2) us(840) rsadsi(113549)
pkcs(1) pkcs-9(9) smime(16) modules(0) msg-v3dot1(21) }
DEFINITIONS IMPLICIT TAGS ::=
BEGIN
IMPORTS
-- Cryptographic Message Syntax
SubjectKeyIdentifier, IssuerAndSerialNumber,
RecipientKeyIdentifier
@rgov
rgov / split-enct2.py
Last active March 3, 2018 09:16
Code to split encipher.it ciphertexts into constituent parts
#!/usr/bin/env python3
import base64
ct = 'EnCt22bbdc932ace27197eff234c409c2550cc882a4c92bbdc932ace27197eff234c4GMRUZdNqXgHr7zwU7FbknCNZzGy2Z143IJuZ3Q==IwEmS'
ct = ct[5:] # trim 'EnCt2' header
ct = ct[:-5] # trim 'IwEmS' footer
hash = bytes.fromhex(ct[:64])
hmac = bytes.fromhex(ct[:40])
def step_waves(waves):
for i in xrange(len(waves)):
if i + 1 < len(waves):
waves[i] += waves[i+1] - 8
# This is almost modulo 15, but not quite
if waves[i] > 15:
waves[i] -= 15
elif waves[i] < 0:
waves[i] += 15
import itertools
# Re-implementation of important methods from the VB code
init_step_count = 1024
def step_waves(waves):
for i in xrange(len(waves)):
if i + 1 < len(waves):
waves[i] += waves[i+1] - 8