-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
114 lines (101 loc) · 5.07 KB
/
Copy pathscript.js
File metadata and controls
114 lines (101 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Function to toggle the menu icon and menu items for mobile view
function toggleMenu() {
var menuItems = document.getElementById("menuItems");
menuItems.classList.toggle("active");
var menuIcon = document.querySelector(".menu-icon");
menuIcon.classList.toggle("change");
}
// Function to handle form submission and hash calculation
document.getElementById("hashForm").addEventListener("submit", function(event) {
event.preventDefault();
var hashType = document.getElementById("hashType").value;
var inputString = document.getElementById("inputString").value;
var fileInput = document.getElementById("fileInput").files[0];
var includeSalt = document.getElementById("includeSalt").checked;
var hashValue = "";
var button = document.querySelector('input[type="submit"]');
button.classList.add("clicked");
// Check if the user has entered a string or selected a file
if (inputString) {
hashValue = calculateHash(inputString, hashType, includeSalt);
displayHash(hashValue);
} else if (fileInput) {
// Read the file and hash its content
var reader = new FileReader();
reader.onload = function(event) {
var fileContent = event.target.result;
hashValue = calculateHash(fileContent, hashType, includeSalt);
displayHash(hashValue);
};
reader.readAsText(fileInput);
} else {
alert("Please enter a string or select a file.");
}
});
// Function to calculate hash based on hash type
function calculateHash(input, hashType, includeSalt) {
if (includeSalt) {
// Generate a random salt (you may use a more secure method for generating salt)
var salt = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
input += salt; // Concatenate salt with input string
}
switch(hashType) {
case "md5":
return CryptoJS.MD5(input).toString();
case "sha1":
return CryptoJS.SHA1(input).toString();
case "sha256":
return CryptoJS.SHA256(input).toString();
case "sha512":
return CryptoJS.SHA512(input).toString();
default:
return "Invalid hash type";
}
}
// Function to display hash value
function displayHash(hash) {
document.getElementById("hashValue").value = hash;
}
function checkHash() {
var hashValue = document.getElementById("hashValue").value;
// Replace 'YOUR_VIRUSTOTAL_API_KEY' with your actual VirusTotal API key
var apiKey = '23a6ae0465a40999898a0fb284e21b1f611d91ca25a8999d54704a97d89b014c';
// VirusTotal API endpoint for hash lookup
var apiUrl = `https://www.virustotal.com/vtapi/v2/file/report?apikey=${apiKey}&resource=${hashValue}`;
// Make a GET request to the VirusTotal API
fetch(apiUrl)
.then(response => response.json())
.then(data => {
// Check the response from VirusTotal
if (data.response_code === 1) {
// File has been scanned and results are available
displayStatus(data.positives > 0);
} else {
// File not found in VirusTotal database
displayStatus(false);
}
})
.catch(error => {
console.error('Error fetching data from VirusTotal:', error);
displayStatus(false);
});
}
// Function to display the status based on VirusTotal results
function displayStatus(isMalicious) {
var statusElement = document.getElementById("status");
statusElement.textContent = isMalicious ? "Malicious" : "Not Malicious";
statusElement.className = isMalicious ? "malicious" : "safe";
}
// Function to copy hash value to clipboard
function copyHashValue() {
var hashValue = document.getElementById("hashValue");
hashValue.select();
hashValue.setSelectionRange(0, 99999); // For mobile devices
document.execCommand("copy");
alert("Hash value copied to clipboard!");
}
// Function to show the main content after loading
window.onload = function() {
document.getElementById("loadingScreen").style.display = "none";
document.querySelector('.container').style.display = "block";
};