Skip to content

Instantly share code, notes, and snippets.

View angeloped's full-sized avatar

Angeloped angeloped

  • Philippines
View GitHub Profile
@angeloped
angeloped / data_compressor.py
Created October 2, 2019 11:41
Lossless data compression code snippet with the help of zlib DEFLATE (Lempel–Ziv 1977) compression algorithm.
#!/bin/python
import base64
import zlib
import sys
"""
name: data_compressor.py
description: Lossless data compression code snippet with the help of zlib DEFLATE (Lempel–Ziv 1977) compression algorithm.
author: Bryan Angelo Pedrosa
"""
@angeloped
angeloped / distributed_key_processing.py
Last active November 22, 2019 12:09
Algorithm for secure multi-circuit encryption key distribution. This will add another extra layer of security when sharing encryption keys for every encrypted requests.
#!/bin/python
# -*- coding: utf-8 -*-
import os
from hashlib import md5
from operator import itemgetter
"""
name: secret_share.py
description: Algorithm for secure multi-circuit key distribution.
@angeloped
angeloped / aes.py
Created September 28, 2019 09:54 — forked from LuoZijun/aes.py
Python AES
#!/usr/bin/env python
#coding: utf8
import base64
import hashlib
import binascii
from Crypto import Random
from Crypto.Cipher import AES
from os import urandom
@angeloped
angeloped / probability-distribution.py
Last active September 26, 2019 13:05
Random choice based on probability distribution.
import random
def weighted_choice(choices):
total = sum(w for c, w in choices)
r = random.uniform(0, total)
upto = 0
for c, w in choices:
if upto + w >= r:
break
upto += w
@angeloped
angeloped / Dispersal-A.py
Last active November 22, 2019 12:08
Dispersal Algorithm (experiment A) that works regardless of python version. Experiment B will be posted next time.
#!/bin/python
# -*- coding: utf-8 -*-
from __future__ import division
import os
import base64
from hashlib import sha256
"""
@angeloped
angeloped / netcat.py
Created September 20, 2019 07:58 — forked from leonjza/netcat.py
Python Netcat
import socket
class Netcat:
""" Python 'netcat like' module """
def __init__(self, ip, port):
self.buff = ""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@angeloped
angeloped / remove_CtrlChars.py
Created September 19, 2019 16:57
Remove control characters (e.g., \n, \r, \x, etc.) with Python, compatible in both Python version 2 and 3.
#!/usr/bin/python
# -*- encoding: utf-8 -*-
import unicodedata
def remove_CtrlChars(string):
try:# Unicode conversion for Python 2
string = string.decode("utf-8")
except:# Unicode conversion for Python 3
string = string.encode().decode("utf-8","strict")
@angeloped
angeloped / fibonacci.py
Last active February 1, 2020 04:40
Fibonacci seqence written in Python.
'''
written by: Bryan Angelo
'''
seq = []
# infinite loop
while 1:
if len(seq) == 0:
seq.append(1)
@angeloped
angeloped / pi.digits
Last active September 15, 2019 10:36
518,650 digits of pi.
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327
@angeloped
angeloped / pi.py
Last active September 13, 2019 06:41 — forked from markhamilton1/pi.py
pi is a Python script that computes each digit of the value of pi. As long as this script runs it continues to generate digits. As a matter of full disclosure, I did not write this. I am posting it here as a means of preserving the algorithm and making it available to others.
import sys
'''
Added some modificationss
1. saving line for every 1024 digits.
2. notify if it scored million.
'''
def calcPi():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3