This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
l = 32 | |
s = bin(int(argv[1], 16))[2:].zfill(l) | |
try: | |
i = 2 | |
while argv[i]: | |
argv[i] = int(argv[i]) | |
s = s[:l-argv[i]] + " " + s[l-argv[i]:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Beren Oguz <beren@berkeley.edu> | |
* | |
* @date 29 July 2017 | |
* | |
* This is a minimal, but functional, implementation of ChaCha20 ciphering | |
* algorithm. Please read and understand RFC 7539 standard here: | |
* https://tools.ietf.org/html/rfc7539 | |
* Please make sure you understand how the memory layout of input to ChaCha20 | |
* works before using this function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cmath import exp | |
from math import pi | |
# A simple class to simulate n-th root of unity | |
# This class is by no means complete and is implemented | |
# merely for FFT and FPM algorithms | |
class NthRootOfUnity: | |
def __init__(self, n, k = 1): | |
self.k = k | |
self.n = n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Beren Oguz <beren@berkeley.edu> | |
# function: multiport_represent_ports | |
# input: arr, a list of port numbers, their type must be int | |
# output: shortest representation that can be passed to `iptables -m multiport` | |
def multiport_represent_ports(arr): | |
min_max = [[i, i] for i in range(len(arr))] # we keep track of min and max of ranges | |
port2id = dict() # port number -> array index | |
id2port = dict() # array index -> port number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Ulam Spiral | |
* http://en.wikipedia.org/wiki/Ulam_spiral | |
* @author Beren Oguz | |
* @copyright 2015, Beren Oguz | |
* @license This code is licensed with BSD-2 clause License | |
* Please see: http://opensource.org/licenses/BSD-2-Clause | |
*/ | |
#include <cstdint> | |
#include <cmath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Wavelength to RGB color | |
* Algorithm from: http://www.efg2.com/Lab/ScienceAndEngineering/Spectra.htm | |
* @author Beren Oguz | |
* @copyright 2015, Beren Oguz | |
* @license This code is licensed with BSD-2 clause License | |
* Please see: http://opensource.org/licenses/BSD-2-Clause | |
*/ | |
#include <cmath> // for std::trunc, std::round, std::pow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @challenge Implement a constexpr variable that has the Unix Timestamp of compilation time | |
* @see https://gist.github.com/berenoguz/a710b60f4a2fd2737fa3 | |
* @usage Check above link: you can use constexpr Mersenne Twister 32 algorithm to have templates that change behavior in each compilation | |
* @author Beren Oguz | |
* @copyright Copyright (c) 2015, Beren Oguz | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @challenge Implement Mersenne Twister 32 algorithm by only using C++ template variables | |
* @see https://gist.github.com/berenoguz/eae088a41f71696a7c11 | |
* @usage You can use random integers for your templates (see above gist), so that behavior of templates will change every compilation | |
* @author Beren Oguz | |
* @copyright Copyright (c) 2015, Beren Oguz | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |