Skip to content

Instantly share code, notes, and snippets.

View HirbodBehnam's full-sized avatar

Hirbod Behnam HirbodBehnam

View GitHub Profile
@HirbodBehnam
HirbodBehnam / ParsePem.cs
Created February 3, 2020 12:40
Just a small app to parse pem files with bouncy castle
// https://stackoverflow.com/questions/7149411/j2me-exception-when-casting-from-pemobject-to-asymmetrickeyparameter-with-bounc
// https://stackoverflow.com/questions/11506891/how-to-load-the-rsa-public-key-from-file-in-c-sharp
// https://stackoverflow.com/questions/11346200/reading-pem-rsa-public-key-only-using-bouncy-castle/11367152#11367152
using System;
using System.Buffers.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@HirbodBehnam
HirbodBehnam / key_derivation_bench.go
Last active March 2, 2020 13:33
Small benchmark of some key derivation algorithms
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/sha512"
"crypto/x509"
"encoding/pem"
"fmt"
package main
import (
"bufio"
"fmt"
"github.com/yourbasic/graph"
"log"
"os"
"strconv"
"strings"
// On my computer (i7-4790K 4.0GHz) the overall time is 571ms
/*
* Simple example of algorithm:
* For example we want to calculate the smallest number that has 2^4 factors that is 120
* We start by calculating prime number from 2 to n; (I'm not very sure how to calculate n)
* After I fill an sorted array named factors just by prime numbers, I start with the smallest one (2)
* I multiply the smallest one in a variable called result with the initial value of 1
* After I multiply smallest value from the sorted list in the result, I remove that value from list, and re-inset value ^ 2
* This makes sure that for each number in the list that we multiply in, the number of factors are doubled.
package main
import (
"bufio"
"fmt"
"github.com/yourbasic/graph"
"log"
"os"
"strconv"
"strings"
package main
import (
"bufio"
"fmt"
"github.com/yourbasic/graph"
"log"
"os"
"strconv"
"strings"
package main
import (
"bufio"
"fmt"
"github.com/yourbasic/graph"
"log"
"os"
"strconv"
"strings"
@HirbodBehnam
HirbodBehnam / dl.sh
Last active October 4, 2020 13:52
A simple google drive downloader
# A script to extract the ID from links like: https://drive.google.com/file/d/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/view?usp=sharing
for arg in "$@"
do
arrIN=(${arg//// })
python3 google-drive-downloader.py "${arrIN[4]}"
done
@HirbodBehnam
HirbodBehnam / url-watcher.sh
Last active June 8, 2020 06:39
A simple script to watch a url for changes
#!/bin/bash
URL="$1"
TOKEN="Telegram Bot Token"
CHAT_ID="Your Chat ID" # for example use @myidbot
temp_file=$(mktemp)
curl -o $temp_file "$URL"
sum=$(md5sum $temp_file)
while :
do
sleep 3600
@HirbodBehnam
HirbodBehnam / TelegramUploader.py
Last active July 12, 2020 12:07
A script to upload file to telegram
# Use the app like python3 TelegramUploader.py /path/to/file
# At first install Telethon and humanize with pip3 install telethon humanize cryptg
# Note that cryptg is optional and only is used for speeding up the uploads
import sys, humanize
from telethon import TelegramClient, events, sync
def upload_progress_callback(downloaded_bytes, total_bytes):
print("Uploaded: " + humanize.naturalsize(downloaded_bytes) + " / " + humanize.naturalsize(total_bytes), end='\r')
# These example values won't work. You must get your own api_id and