Skip to content

Instantly share code, notes, and snippets.

View sachadee's full-sized avatar

SachaDee sachadee

View GitHub Profile
@sachadee
sachadee / decryptaes.js
Created November 14, 2021 03:58
AES encryption in JavaScript
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<script>
//JS FIX IV ENCRYPTION CBC
var message = 'I love Medium';
var key ='AAAAAAAAAAAAAAAA'//key used in Python
key = CryptoJS.enc.Utf8.parse(key);
var iv = CryptoJS.enc.Utf8.parse('BBBBBBBBBBBBBBBB')
var encrypted = CryptoJS.AES.encrypt(message, key, { iv: iv, mode: CryptoJS.mode.CBC});
encrypted =encrypted.toString();
console.log('encrypted',encrypted );
@sachadee
sachadee / aesecb.js
Last active June 16, 2023 02:27
AES ECB decryption in JavaScript
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<script>
var encrypted ='gfp6wzvTH3lN5TO2B37yWQ=='; //python is base64 ECB
var key ='AAAAAAAAAAAAAAAA'//key used in Python
key = CryptoJS.enc.Utf8.parse(key);
var decrypted = CryptoJS.AES.decrypt(encrypted, key, {mode:CryptoJS.mode.ECB});
console.log(decrypted.toString(CryptoJS.enc.Utf8));
</script>
@sachadee
sachadee / eascbc.js
Last active June 16, 2023 04:38
AES CBC Decryption in JavaScript
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<script>
//PYTHON FIX IV ENCRYPTION AND PYTHON FIX IV
var Base64CBC ='VEX7Eequ5TM9+jlgrwnkNw==';
var iv = CryptoJS.enc.Utf8.parse('BBBBBBBBBBBBBBBB');
//PYTHON RANDOM IV ENCRYPTION AND PYTHON RANDOM IV
//var Base64CBC ='uJrS9Zp1R5WjOEUkSK9clQ==';
//var iv = CryptoJS.enc.Base64.parse('l5I5Toqn5RoX0JfTLQB9Pw==');
var key ='AAAAAAAAAAAAAAAA'//key used in Python
key = CryptoJS.enc.Utf8.parse(key);
@sachadee
sachadee / aesecb.py
Last active November 6, 2024 08:12
Python AES ECB Encryption
import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpad
#AES ECB mode without IV
data = 'I love Medium'
key = 'AAAAAAAAAAAAAAAA' #Must Be 16 char for AES128
def encrypt(raw):
@sachadee
sachadee / aescbcfixiv.py
Last active November 16, 2021 12:45
AES CBC Encryption python with fix IV
import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpad
#CBC with Fix IV
data = 'I love Medium'
key = 'AAAAAAAAAAAAAAAA' #16 char for AES128
#FIX IV
@sachadee
sachadee / aescbcrandomiv.py
Last active November 16, 2021 12:43
AES CBC encryption random IV
import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpad
from Crypto.Random import get_random_bytes
#CBC mode with random IV
data = 'I love Medium'
key = 'AAAAAAAAAAAAAAAA' #16 char for AES128
@sachadee
sachadee / createimagetensor.py
Last active May 7, 2022 06:56
Create a Pytorch Tensor of an image
import torch
import numpy as np
import cv2
import torchvision.transforms as transforms
from PIL import Image
# Read the image with openCV
# image = cv2.imread('sachadee.jpg')
# Convert BGR image to RGB image
@sachadee
sachadee / tensorinfo.py
Last active May 7, 2022 06:55
tensor info
#Base Image
print("Image Dtype:", np.array(image).dtype)
print("Image shape:", np.array(image).shape)
print('***********')
#Tensor image
print("Tensor Dtype:", tensor.dtype)
print("Tensor shape:", tensor.shape)
tensor_to_pil = transforms.ToPILImage()(tensor)
tensor_to_pil.show()
@sachadee
sachadee / arcface
Created May 7, 2022 07:59
arcfaceproblem
# get embedding for each face
embeddings = np.zeros([len(loader.dataset), embedding_size])
with torch.no_grad():
for idx, (image, _) in enumerate(
tqdm(loader, desc="Create embeddings matrix", total=len(loader)),
):
print(idx)
embeddings[idx, :] = F.normalize(backbone(image.to(device))).cpu()
tensor_to_pil = transforms.ToPILImage()(image.squeeze_(0)).convert('RGB')
tensor_to_pil.show()