Created
September 18, 2019 01:29
-
-
Save maxjf1/9fb15b6e14ec2c4dee2bf8b757855610 to your computer and use it in GitHub Desktop.
Exercicios Segurança
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
const pAlice = 6, // Chave privada Alice | |
pBob = 5, // Chave privada Bob | |
primo = 23, | |
a = 8; | |
// chaves secretas compartilhadas | |
let kBob, kAlice; | |
function main() { | |
const compBob = gerarChaveCompartilhada(primo, pBob, a); | |
const compAlice = gerarChaveCompartilhada(primo, pAlice, a); | |
kAlice = calculaChaveSecretaCompartilhada(primo, compBob, pAlice); | |
kBob = calculaChaveSecretaCompartilhada(primo, compAlice, pBob); | |
} | |
function gerarChaveCompartilhada(primo, privada, c) { | |
return Math.pow(c, privada) % primo; | |
} | |
function calculaChaveSecretaCompartilhada(primo, publica, privada) { | |
return Math.pow(publica, privada) % primo; | |
} | |
main(); | |
const response = `Chaves: Bob: ${kBob} = Alice: ${kAlice}`; | |
console.log(response); | |
document.write(response); |
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
const SIZE = 100; | |
let vetor = [], | |
VetorFrequencia = {}, | |
rodadas = 0, | |
valorAleatorio; | |
function getRandom() { | |
return Number.parseInt(Math.random() * SIZE); | |
} | |
while (rodadas < SIZE * 1000) { | |
valorAleatorio = getRandom(); | |
for (let i = 0; i < SIZE; i++) { | |
vetor[i] = getRandom(); | |
} | |
vetor.forEach(element => { | |
if (element === valorAleatorio) { | |
VetorFrequencia[valorAleatorio] = (VetorFrequencia[valorAleatorio] || 0) + 1; | |
} | |
}); | |
rodadas++; | |
} | |
console.log(VetorFrequencia); | |
document.write(`<pre>${JSON.stringify(VetorFrequencia, null, 4)}</pŕe>`); | |
// saída | |
{ | |
"0": 1075, | |
"1": 987, | |
"2": 979, | |
"3": 1011, | |
"4": 996, | |
"5": 969, | |
"6": 903, | |
"7": 1029, | |
"8": 1025, | |
"9": 957, | |
"10": 1018, | |
"11": 1065, | |
"12": 952, | |
"13": 942, | |
"14": 1020, | |
"15": 1047, | |
"16": 993, | |
"17": 1091, | |
"18": 987, | |
"19": 941, | |
"20": 961, | |
"21": 988, | |
"22": 1023, | |
"23": 938, | |
"24": 1020, | |
"25": 1084, | |
"26": 911, | |
"27": 983, | |
"28": 1024, | |
"29": 1139, | |
"30": 982, | |
"31": 941, | |
"32": 1010, | |
"33": 975, | |
"34": 987, | |
"35": 1070, | |
"36": 1074, | |
"37": 990, | |
"38": 1076, | |
"39": 1009, | |
"40": 1018, | |
"41": 942, | |
"42": 1029, | |
"43": 1044, | |
"44": 916, | |
"45": 1001, | |
"46": 1023, | |
"47": 947, | |
"48": 1002, | |
"49": 1041, | |
"50": 966, | |
"51": 1036, | |
"52": 952, | |
"53": 1012, | |
"54": 986, | |
"55": 1012, | |
"56": 1117, | |
"57": 943, | |
"58": 966, | |
"59": 986, | |
"60": 997, | |
"61": 1059, | |
"62": 1056, | |
"63": 972, | |
"64": 961, | |
"65": 1002, | |
"66": 957, | |
"67": 1129, | |
"68": 1114, | |
"69": 1004, | |
"70": 930, | |
"71": 966, | |
"72": 1044, | |
"73": 1084, | |
"74": 980, | |
"75": 993, | |
"76": 1051, | |
"77": 1019, | |
"78": 993, | |
"79": 1024, | |
"80": 968, | |
"81": 1005, | |
"82": 964, | |
"83": 958, | |
"84": 973, | |
"85": 962, | |
"86": 981, | |
"87": 1012, | |
"88": 890, | |
"89": 989, | |
"90": 992, | |
"91": 974, | |
"92": 1043, | |
"93": 1053, | |
"94": 989, | |
"95": 996, | |
"96": 977, | |
"97": 981, | |
"98": 958, | |
"99": 1004 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment