Skip to content

Instantly share code, notes, and snippets.

View codelance's full-sized avatar

Brandon Brisbon codelance

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / DataNode.java
Created December 2, 2012 01:17
Java Stack Based Linked List
public class DataNode {
/*DataNode Constructor
Description: Called when an object is instantiated
Parameters:
Object Elem : object stored as data in this class
Pre: None
Post: Initialized element
@codelance
codelance / fibonacci.java
Created December 2, 2012 01:10
Fibonacci
private static int gfib(int f0, int f1, int n)
{
switch( n )
{
case 0:
return f0;
case 1:
return f1;
default:
return gfib(f0,f1, n-1 ) + gfib(f0, f1, n+1);
private static int gcd(int x, int y){
if( y <= x & (x%y) == 0)
return y;
else if( x < y)
return gcd(y,x);
else
return gcd(y, x % y);
}
private static int iterativegcd(int x, int y)
@codelance
codelance / binary_search.java
Created December 2, 2012 01:09
Binary Search
private static int binarySearch( int[ ] a, int toFind, int low, int high )
{
if( low > high )
return -1;
int mid = ( low + high ) / 2;
if( a[ mid ] > toFind )
return binarySearch( a, toFind, mid + 1, high );
else if( a[ mid ] < toFind )