<commit_before>from Crypto.Cipher import AES
import base64
import hashlib
import datetime
import urllib
import pytz
import simplejson as json

def generate_sso_token(subdomain_name, sso_key, user_attributes):
    current_time = (datetime.datetime.now(pytz.utc) + datetime.timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')
    user_attributes.setdefault('expires', current_time)
    user_json = json.dumps(user_attributes, separators=(',',':'))
    iv = "OpenSSL for Ruby"
    block_size = 16

    salted = sso_key + subdomain_name
    saltedHash = hashlib.sha1(salted).digest()[:16]

    json_bytes = array.array('b', user_json[0 : len(user_json)])
    iv_bytes = array.array('b', iv[0 : len(iv)])

    for i in range(0, 16):
        json_bytes[i] = operator.xor(json_bytes[i], iv_bytes[i])

    pad = block_size - len(json_bytes.tostring()) % block_size
    data = json_bytes.tostring() + pad * chr(pad)
    aes = AES.new(saltedHash, AES.MODE_CBC, iv)
    encrypted_bytes = aes.encrypt(data)

    return urllib.quote(base64.b64encode(encrypted_bytes))

<commit_msg>Need to import these for clean environment.<commit_after>from Crypto.Cipher import AES
import base64
import hashlib
import datetime
import urllib
import pytz
import array
import operator
import simplejson as json

def generate_sso_token(subdomain_name, sso_key, user_attributes):
    current_time = (datetime.datetime.now(pytz.utc) + datetime.timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')
    user_attributes.setdefault('expires', current_time)
    user_json = json.dumps(user_attributes, separators=(',',':'))
    iv = "OpenSSL for Ruby"
    block_size = 16

    salted = sso_key + subdomain_name
    saltedHash = hashlib.sha1(salted).digest()[:16]

    json_bytes = array.array('b', user_json[0 : len(user_json)])
    iv_bytes = array.array('b', iv[0 : len(iv)])

    for i in range(0, 16):
        json_bytes[i] = operator.xor(json_bytes[i], iv_bytes[i])

    pad = block_size - len(json_bytes.tostring()) % block_size
    data = json_bytes.tostring() + pad * chr(pad)
    aes = AES.new(saltedHash, AES.MODE_CBC, iv)
    encrypted_bytes = aes.encrypt(data)

    return urllib.quote(base64.b64encode(encrypted_bytes))


{'fraction_non_alphanumeric': 0.1334851936218679, 'fraction_numerical': 0.015489749430523917, 'mean_word_length': 4.517587939698492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2176069', 'n_tokens_mistral': 827, 'n_tokens_neox': 779, 'n_words': 158}