Skip to content

Instantly share code, notes, and snippets.

View 17twenty's full-sized avatar

Nick Glynn 17twenty

View GitHub Profile
@17twenty
17twenty / lambdaTest.cpp
Created July 1, 2014 15:04
Not sure how I feel about C++11s Lambda operations :-/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
@17twenty
17twenty / ohexploitable.c
Created September 1, 2014 13:50
Of buffers and exploitables
#include <stdio.h>
#include <string.h>
void giveControl(const char * username)
{
printf("Granted access\n");
}
void authUser(char * username) //, char * password)
{
@17twenty
17twenty / badstings.c
Created September 5, 2014 11:53
Urgh, C strings suck
#include <string.h>
#include <stdio.h>
void printCanary(char * first, char * second)
{
printf("Canaries[%c%c] [%c%c]\n", first[0], first[1], second[0], second[1]);
memset(first, 'X', 2 * sizeof(*first));
memset(first, 'Z', 2 * sizeof(*second));
}
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>
char chutz = 43;
@17twenty
17twenty / amazon.py
Created October 1, 2014 18:10
Amazon coding test
#!/usr/bin/env python
import sys
N,K = (int(val) for val in sys.stdin.readline().split())
setN = [int(val) for val in sys.stdin.read().split()]
# Should we check len(setN) <= N?
# We should sort such that we can optimise
setN.sort()
@17twenty
17twenty / baseConverter.py
Created October 1, 2014 18:09
Simple baseconverter in Python
#!/usr/bin/env python
def baseConverter(num, base = 2):
vals = []
digits = "0123456789abcdef"
while num > 0:
remainder = num % 2
vals.append(remainder)
num = num // base
@17twenty
17twenty / bitshift.c
Created January 28, 2015 10:31
Bitshifting Source and Header
#include <stdio.h>
#include "bitshift.h"
int main()
{
unsigned char ascii_char = 'A'; /* char = 8 bits only */
int test_nbr = 10;
printf("Starting character = %08X\n", ascii_char);
/* The 5th bit position determines if the character is
uppercase or lowercase.
@17twenty
17twenty / doAverage.c
Created February 2, 2015 12:58
Examples of using vaargs in C
#include <stdarg.h>
double average(int count, ...)
{
va_list ap;
int j;
double tot = 0;
va_start(ap, count); /* Requires the last fixed parameter (to get the address) */
for(j = 0; j < count; j++)
tot += va_arg(ap, double); /* Increments ap to the next argument. */
@17twenty
17twenty / arrayItemPass.c
Created February 2, 2015 12:52
Correct handling of array items in C
#include <stdio.h>
#define ARRAY_SIZE(x) \
((sizeof(x) / sizeof(x[0])))
void count_and_process_items(unsigned int (*array)[10])
{
for (int i = 0; i < ARRAY_SIZE(*array); ++i) {
printf("Item %d = %d\n", i, (*array)[i]);
printf("\twhich should also be %d\n", (i)[*array]);
@17twenty
17twenty / pyng.py
Created February 2, 2015 12:53
Python Implementation of Ping
#!/usr/bin/env python
"""
A pure Python "ping" implementation, based on a rewrite by Johannes Meyer,
of a script originally by Matthew Dixon Cowles. Which in turn was derived
from "ping.c", distributed in Linux's netkit. The version this was forked
out of can be found here: https://gist.github.com/pklaus/856268
The versions this script derived from are licensed under GPL v2, this makes
mandatory that this is licensed under the same terms as well. If it were up