Skip to content

Instantly share code, notes, and snippets.

View syzdek's full-sized avatar

David M. Syzdek syzdek

  • Anchorage, Alaska
View GitHub Profile
@syzdek
syzdek / locky-dga.c
Last active February 25, 2016 07:24
Locky Ransomware Domain Generation Algorithm
/*
* Locky Ransomware Domain Generation Algorithm
*
* Original code from Forcepoint Security Labs:
* https://blogs.forcepoint.com/security-labs/locky-ransomware-encrypts-documents-databases-code-bitcoin-wallets-and-more
*
* Code updated by David M. Syzdek <ten . kedzys @ divad> on 2016/02/24
*
* Compile with:
* gcc -W -Wall -Werror -o locky-dga locky-dga.c
/*
* TOTP: Time-Based One-Time Password Algorithm
* Copyright (c) 2015, David M. Syzdek <david@syzdek.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
#!/bin/bash
# set parameters
TOTP_UID=${1:-$UID}
TOTP_CODE=${2:-123456}
# encode numeric UID into three port numbers
TOTP_PORT1=$(( $(( ${TOTP_UID} / 4194304)) + 4096 ))
TOTP_PORT2=$(( $(( $(( ${TOTP_UID} % 4194304)) / 16384 )) + 4096 ))
TOTP_PORT3=$(( $(( $(( ${TOTP_UID} % 4194304)) % 16384 )) + 4096 ))
@syzdek
syzdek / ipv6-regex-test.sh
Last active March 20, 2024 11:09
Simple script to test my IPv6 regular expression.
#!/bin/sh
#
# Use posixregex CLI tool from: https://github.com/syzdek/dmstools/blob/master/src/posixregex.c
RE_IPV4="((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"
posixregex -r "^(${RE_IPV4})$" \
127.0.0.1 \
10.0.0.1 \
192.168.1.1 \
// Program to strip comments and strings from a C file
//
// Answer to StackOverflow question:
// http://stackoverflow.com/questions/16086617/c-removing-comments-with-a-sliding-window-without-nested-while-loops
//
// Build:
// gcc -o strip-comments strip-comments.c
//
// Test:
// ./strip-comments strip-comments.c
/*
* simple Iv4/IPv6 TCP server which echos any data sent to the open port
*/
#include <stdio.h>
#include <poll.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
@syzdek
syzdek / gist:4449236
Created January 4, 2013 01:47
Generates a tile image from an input image.
- (UIImage *) tileImageFromImage:(UIImage *)image
{
CGImageRef imageRef;
CGContextRef context;
CGColorSpaceRef color;
CGFloat w;
CGFloat h;
CGFloat r;
CGFloat m;
NSInteger pos;
intmax_t sqroot_imax(intmax_t n, int round)
{
intmax_t op = n;
intmax_t res = 0;
intmax_t one = 1uL << ((sizeof(intmax_t)*8)-2);
// "one" starts at the highest power of four <= than the argument.
while (one > op)
one >>= 2;
@syzdek
syzdek / mword crossword stats (strip 'qu').txt
Created November 28, 2012 22:50
Word and Letter statistics from an English lexicon.
Dictionary Stats:
Words Dropped: 23*
Words Duplicated: 0
Words Indexed: 117946
----------------------------
Total Words Parsed: 117969**
* Words with a 'q' not immediately followed by a 'u' (e.g "qiviut").
** The 'u' following a 'q' have been striped from the word (e.g. "quilting"
becomes "qilting"). The 'u' is implied by a 'q' in some word tile/dice
@syzdek
syzdek / cli-nsrunloop.m
Created July 31, 2012 21:36
Creating an NSRunLoop for a command line utility.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSRunLoop * runLoop;
CLIMain * main; // replace with desired class
@autoreleasepool
{
// create run loop