This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tensor_to_pil = transforms.ToPILImage()(tensor) | |
tensor_to_pil.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
OlderNewer