Skip to content

Instantly share code, notes, and snippets.

View nboubakr's full-sized avatar

Boubakr nboubakr

  • Montreal, Canada
View GitHub Profile
@nboubakr
nboubakr / HuffmanCoding.py
Created January 1, 2015 11:35
Huffman coding implementation in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Le codage de Huffman
# Théorie de l'information et du codage
# Etudiant: Boubakr NOUR <n.boubakr@gmail.com>
# Universite Djilali Liabes (UDL) de Sidi Bel Abbes
import heapq
from collections import defaultdict
@nboubakr
nboubakr / LZ78.py
Created December 30, 2014 23:15
Lampel-Ziv 78 (LZ78) implementation in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Lampel-Ziv 78 (LZ78)
# Théorie de l'information et du codage
# Etudiant: Boubakr NOUR <n.boubakr@gmail.com>
# Universite Djilali Liabes (UDL) de Sidi Bel Abbes
def compress(data):
dictionary, word = {0: ''}, 0
@nboubakr
nboubakr / union.py
Created December 10, 2014 21:36
Union of two sorted sequences (A and B aren't empty)
def union(A, i, B, j, C):
if (i >= len(A)) and (j >= len(B)) and (max(A[-1], B[-1]) == C[-1]):
return C
if (i == len(A)) and (j <= len(B)) and (C[-1] < B[j]):
C.append(B[j])
return union(A, i, B, j + 1, C)
if (j == len(B)) and (i <= len(A)) and (C[-1] < A[i]):
C.append(A[i])
@nboubakr
nboubakr / Ackermann.java
Created November 21, 2014 20:44
Ackermann Function: recursive and non recursive version
import java.util.Stack;
/**
*
* @author Boubakr
*/
public class Ackermann {
public static int RecursiveAckerman(int m, int n) {
if (m == 0) {
@nboubakr
nboubakr / random_mac_address.py
Created May 10, 2014 11:08
Generate a random MAC Address using the VM OUI code.
import random
def generate_random_mac_address():
"""Generate a random MAC Address using the VM OUI code"""
rand_mac_addr = [0x00, 0x50, 0x56, random.randint(0x00, 0x7f), random.randint(0x00, 0xff), random.randint(0x00, 0xff)]
return ':'.join(map(lambda x: "%02x" % x, rand_mac_addr))
@nboubakr
nboubakr / createDirectory.java
Created February 20, 2014 13:56
This function allows you to create a directory on the user home directory.
private static void createDirectory(final String directoryName) {
final File homeDirectory = new File(System.getProperty("user.home"));
final File newDirectory = new File(homeDirectory, directoryName);
if(!newDirectory.exists()) {
boolean result = newDirectory.mkdir();
if(result) {
System.out.println("The directory is created !");
}
} else {
@nboubakr
nboubakr / DownloadFile.cs
Created December 5, 2013 19:36
Simple function in C# to download a file from the internet, supports to resume the download.
public static void downloadFile(string sourceURL, string destinationPath)
{
long fileSize = 0;
int bufferSize = 1024;
bufferSize *= 1000;
long existLen = 0;
System.IO.FileStream saveFileStream;
if (System.IO.File.Exists(destinationPath))
{
@nboubakr
nboubakr / IsValidAddress.java
Created October 14, 2013 16:26
Check if an IPv6 is a valid address or not.
public boolean IsValidAddress(String ipAddr) {
int nDC = 0;
int nC = 0;
ipAddr = ipAddr.trim();
String s = ipAddr;
char[] chars = s.toCharArray();
/* 0- Error: Empty */
if (s.isEmpty()) {
@nboubakr
nboubakr / ThreeWayHandshaking.py
Created September 23, 2013 13:18
Three Way Handshaking using Scapy
#!/usr/bin/env python
#! -*- coding: utf-8 -*-
# Three Way Handshaking using Scapy
from scapy.all import *
ip = IP(src="192.168.0.2", dst="172.16.24.1")
SYN = TCP(sport=1500, dport=80, flags='S', seq=100)
SYNACK = sr1(ip/SYN)
@nboubakr
nboubakr / enumerate-string.py
Created March 21, 2013 21:38
Enumerate a string to substrings
#!/usr/bin/env python
#! -*- coding: utf-8 -*-
# Enumerate a string to substrings
# Y is a substring for X if: X = U.Y.V
def enumerate(string):
"""Function that will enumerate a string to substring
return: A list with all the substrings