Skip to content

Instantly share code, notes, and snippets.

View mudssrali's full-sized avatar
🕸️
Crafting software solutions for better, at scale

Mudassar mudssrali

🕸️
Crafting software solutions for better, at scale
View GitHub Profile
@mudssrali
mudssrali / erlang-elixir-crypto_one_time.ex
Last active September 7, 2021 01:59
Implementation of erlang's :crypto.crypto_one_time/5 API with base64 encoding in elixir
defmodule AES do
@block_size 16
@secret_key "write something secret"
def encrypt(text) do
secret_key_hash = hash(@secret_key, 32)
# create random Initialisation Vector
iv = :crypto.strong_rand_bytes(16)
text = pad(text, @block_size)
@mudssrali
mudssrali / aes-nodejs-service.js
Created September 14, 2021 04:09
a simple AES service to encrypt and decrypt plaintext
const express = require("express");
const cors = require('cors');
const crypto = require('crypto-js');
const PORT = process.env.PORT ?? 8080;
const HOST = process.env.HOST ?? '0.0.0.0';
const SECRET_KEY = process.env.SECRET_KEY ?? "write something secret here";
const app = express();
app.use(cors());
@mudssrali
mudssrali / erlang-elixir-aes-crypto.ex
Last active September 15, 2021 20:56
Elixir implementation of encryption and decryption using erlang's :crypto.block_encrypt and :crypto.block_decrypt
defmodule Crypto.AES do
@block_size 16
@secret_key ""
def encrypt(text) do
secret_key_hash = make_hash(@secret_key, 16)
text = pad_pkcs7(text, @block_size)
encrypted_text = :crypto.block_encrypt(:aes_ecb, secret_key_hash, text)
Base.encode64(encrypted_text)
@mudssrali
mudssrali / php-openssl-crypto.php
Created September 15, 2021 20:45
Php implementation of encryption and decryption using openssl_encrypt and openssl_decrypt
<?php
$ENCRYPTION_KEY = '';
$ENCRYPTION_ALGORITHM = 'AES-128-ECB';
function encrypt($plainText) {
global $ENCRYPTION_KEY;
global $ENCRYPTION_ALGORITHM;
$EncryptionKey = makeHash($ENCRYPTION_KEY, 16);
$encryptedText = openssl_encrypt($plainText, $ENCRYPTION_ALGORITHM, $EncryptionKey);
@mudssrali
mudssrali / elixir-crypto-one-time.ex
Last active December 10, 2024 09:37
Elixir implementation of AES encryption and decryption using erlang's :crypto.crypto_one_time with initialization vector
defmodule Cipher.AES do
@moduledoc """
Functions related to encrypting and decrypting data using the Advanced
Encryption Standard (AES).
"""
@block_size 16
@secret_key "put something secret here"
@doc """
@mudssrali
mudssrali / php-openssl-crypto-with-iv.php
Created September 15, 2021 22:28
PHP implementation of AES encryption and decryption using openssl_encrypt and openssl_decrypt with initialization vector
<?php
$ENCRYPTION_KEY = "put something secret here";
$ENCRYPTION_ALGORITHM = 'AES-256-CBC';
function encrypt($plain_text) {
global $ENCRYPTION_KEY;
global $ENCRYPTION_ALGORITHM;
$EncryptionKey = make_hash($ENCRYPTION_KEY, 32);
// create random Initialization Vector
@mudssrali
mudssrali / open_browser.ex
Created August 20, 2022 09:26
Open a browser with URL in Elixir
def browser_open(url) do
win_cmd_args = ["/c", "start", String.replace(url, "&", "^&")]
cmd_args =
case :os.type() do
{:win32, _} ->
{"cmd", win_cmd_args}
{:unix, :darwin} ->
{"open", [url]}
@mudssrali
mudssrali / snippets-for-array-generation.js
Created September 19, 2022 04:04
Snippets for array generation in JavaScript
// [0, 0, 0]
Array(3).fill(0);
Array.from(Array(3), () => 0);
// [0, 2, 4, 6, 8]
Array.from(Array(5), (_, index) => index * 2);
// Array of 5 random numbers
Array.from(Array(5), Math.random());
@mudssrali
mudssrali / snippets-for-list-generation.ex
Created September 19, 2022 04:30
Snippets for list generation in Elixir
# Using for construct
# [0, 0, 0]
for _x <- 0..2, do: 0
# [0, 2, 4, 6, 8]
for x <- 0..4, do: x * 2
# List of 5 random numbers
for _x <- 0..4, do: System.unique_integer([:positive])
@mudssrali
mudssrali / geocodes.js
Created November 23, 2022 03:39
Read addresses from Pk-Cashpoints CSV and try to get geo-codes using Geolocation API
const fs = require('fs')
const axios = require('axios');
const Papa = require("papaparse");
fs.readFile('sample.csv', 'utf8', (err, data) => {
if (err) {
return console.error(err)
}
const [headers, ...parsedCSVData] = Papa.parse(data).data