Skip to content

Instantly share code, notes, and snippets.

View codelance's full-sized avatar

Brandon Brisbon codelance

View GitHub Profile
@codelance
codelance / unzip.java
Created December 2, 2012 01:19
Unzip
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@codelance
codelance / HeapSort.java
Created December 2, 2012 01:21
Heap Sort
public class HeapSort {
/*heapsort
Description: Performs a heap sort on a given list
Parameters:
int[] list: array of integers to be sorted
Pre: Initialized array
Post: Sorted array
Returns: Sorted array
@codelance
codelance / ShellSort.java
Created December 2, 2012 01:21
Shell Sort
public class ShellSort {
/*shellsort
Description: Performs a shell sort on a given list
Parameters:
int[] list: array of integers to be sorted
int[] increments: array of bucket sizes
Pre: Initialized array
Post: Sorted array
Returns: Sorted array
@codelance
codelance / StraightInsertionSort.java
Created December 2, 2012 01:22
Straight Insertion Sort
public class StraightInsertionSort {
/*insertionsort
Description: Performs a insertion sort on a given list
Parameters:
int[] list: array of integers to be sorted
Pre: Initialized array
Post: Sorted array
Returns: Sorted array
@codelance
codelance / modinv.java
Created December 2, 2012 01:26
Mod Inverse
static int modinv(int a, int b)
{
int a0 = a;
int b0 = b;
int t0 = 0;
int t = 1;
int q = (int)Math.floor( a0 / b0 );
int r = a0 - (q * b0);
@codelance
codelance / CeasarCipherBreak
Created December 2, 2012 01:29
Ceasar Cipher Break
public static void main(String[] args) {
String ciphertext = "HSPAASLJPWOLYALEAJVBSKILHWYVISLTIBAUVAPMPAPZHZOPMAJPWOLY";
for(int shiftKey = 0; shiftKey < 26; shiftKey++)
{
String plainText = "";
for (int i=0; i<ciphertext.length(); i++)
{
@codelance
codelance / SubstitutionCipher.java
Created December 2, 2012 01:37
Substitution Cipher
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public class SubstitutionCipher {
@codelance
codelance / QuantumKeySimulator
Created December 2, 2012 01:38
Quantum Key Simulator
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Vector;
enum Photon { ZERO, ONE, UNDEFINED; };
class KeyBit {
KeyBit(Photon setBit, String setPol){bit = setBit; polarization = setPol;}
public Photon bit;
public String polarization;
public String toString()
@codelance
codelance / VernamCipher.java
Created December 2, 2012 01:39
Vernam Cipher
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
public class AES {