Last active
October 17, 2015 22:17
-
-
Save itolosa/7c7f2dc5112c13654297 to your computer and use it in GitHub Desktop.
mi version del password del dia para Arris
This file contains hidden or 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
#!/usr/bin/env python | |
# Version limpia del generador de: password-of-the-day | |
# ------------------------------------------------------------ | |
# El generador se trata de cifrado desplazado del seed inicial | |
# considerando el seed total un string infinito circular | |
# que en realidad es el mismo seed repetido infinitas veces. | |
# para esto se utiliza el modulo del largo del seed. (index % largo) | |
# | |
# Los desplazamientos que se utilizan para cada caracter | |
# son calculados con matrices que tienen datos predeterminados | |
# por el mismo algoritmo del router y aplicando operaciones | |
# matematicas sobre ellos (sumas entre los mismos numeros mayormente). | |
# | |
# Finalmente se aplican los desplazamientos a cada numero ascii | |
# de cada caracter del seed y se aplica modulo 36 (% 36) para asegurar | |
# que cada desplazamiento este dentro del rango del alfabeto (alphanum). | |
# | |
import datetime | |
seed = 'vtr2014' #'MPSJKMDHAI' | |
week_shifts_matrix = [ | |
[15, 15, 24, 20, 24], | |
[13, 14, 27, 32, 10], | |
[29, 14, 32, 29, 24], | |
[23, 32, 24, 29, 29], | |
[14, 29, 10, 21, 29], | |
[34, 27, 16, 23, 30], | |
[14, 22, 24, 17, 13] | |
] | |
lookup_matrix = [ | |
[0, 1, 2, 9, 3, 4, 5, 6, 7, 8], | |
[1, 4, 3, 9, 0, 7, 8, 2, 5, 6], | |
[7, 2, 8, 9, 4, 1, 6, 0, 3, 5], | |
[6, 3, 5, 9, 1, 8, 2, 7, 4, 0], | |
[4, 7, 0, 9, 5, 2, 3, 1, 8, 6], | |
[5, 6, 1, 9, 8, 0, 4, 3, 2, 7] | |
] | |
alphanum = ( | |
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', | |
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', | |
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' | |
) | |
def calculate_shifts(day_of_week, day_of_month, year, month, seed): | |
# get initial shifts from matrix | |
date_shifts = list(week_shifts_matrix[day_of_week]) | |
# appends day of the actual month | |
date_shifts.append(day_of_month) | |
# appends date math calculation | |
# if negative it counts in reverse ((auxsum + 36) % 36) | |
auxsum = (year + month) - day_of_month | |
date_shifts.append(auxsum % 36) | |
# another calculation | |
date_shifts.append((((3 + ((year + month) % 12)) * day_of_month) % 37) % 36) | |
# add ascii codes to previously calculated shifts | |
# and creates a new calculated_shifts list | |
calculated_shifts = [] | |
for i in range(8): | |
seed_shift = ord(seed[i % seedlen]) % 36 | |
date_shift = date_shifts[i] | |
total_shift = seed_shift + date_shift | |
calculated_shifts.append(total_shift) | |
# appends a sum of calculated shifts | |
shift = sum(calculated_shifts) % 36 | |
calculated_shifts.append(shift) | |
# index for lookup matrix | |
shift_num8 = shift % 6 | |
# appends the index for lookup by square | |
calculated_shifts.append(int(shift_num8 ** 2)) | |
# filter shifts by lookup matrix indexes row | |
lookup_list = lookup_matrix[shift_num8] | |
filtered_shifts = [] | |
for index in lookup_list: | |
shift = calculated_shifts[index] | |
filtered_shifts.append(shift) | |
return filtered_shifts | |
now = datetime.datetime.now() | |
year = now.year % 100 | |
month = now.month | |
day_of_month = now.day | |
day_of_week = now.weekday() | |
seedlen = len(seed) | |
# gets shifts for cipher then adds to ascii resized (by 36) | |
password_of_the_day = [] | |
shifts = calculate_shifts(day_of_week, day_of_month, year, month, seed) | |
for i in range(len(shifts)): | |
char_index = ord(seed[i % seedlen]) | |
shift = shifts[i] | |
char_index = (char_index + shift) % 36 | |
pass_character = alphanum[char_index] | |
password_of_the_day.append(pass_character) | |
# transform to string | |
print ''.join(password_of_the_day); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment