Complete rework to not use server side code, added no encrypt option
This commit is contained in:
parent
787dba30a3
commit
d552be851f
0
aes.min.js
vendored
Normal file → Executable file
0
aes.min.js
vendored
Normal file → Executable file
12
index.html
Normal file → Executable file
12
index.html
Normal file → Executable file
@ -10,7 +10,7 @@
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.10/clipboard.min.js" integrity="sha384-f7wOtFps7eeIwcPoS0BT08o/onjsbd16QnjQmOoqVIimY7dzcSzfDU/htuPJlTFX" crossorigin="anonymous"></script>
|
||||
<script src="./aes.min.js"></script>
|
||||
<script src='./aes.min.js'></script>
|
||||
<link rel='stylesheet' href='./theme.min.css'>
|
||||
|
||||
</head>
|
||||
@ -45,15 +45,19 @@
|
||||
<textarea id='text' placeholder=''></textarea>
|
||||
</div><br><br>
|
||||
<div class='center'>
|
||||
<div id='one'><button id='toggle' class='btn btn-primary'>Encrypt Mode</button></div>
|
||||
<label>Use Encryption <input type='checkbox' id='useEncrypt' checked></label>
|
||||
<br><br>
|
||||
<div id='one'><button id='toggle' class='btn btn-primary'>Encode <i class='fa fa-lock'></i></button></div>
|
||||
<span id='encryptArea'>
|
||||
<input type='password' id='password' placeholder='Encryption password' class='dataItem'>
|
||||
<br>
|
||||
<input type='password' id='confirmPass' placeholder='Confirm password' class='dataItem'>
|
||||
<br>
|
||||
</span>
|
||||
<button id='go' class='btn btn-success btn-lg dataItem'>Go</button>
|
||||
</div>
|
||||
<footer class='center'>By using this service you agree to our <a href='/legal/'>terms</a>.</footer>
|
||||
<footer class='center'><a href='https://github.com/beardog108/snow2/releases/'>Available for Windows/Linux</a> (Offers increased security)<br>By using this service you agree to our <a href='/legal/'>terms</a>.</footer>
|
||||
</div>
|
||||
<script src='./main.min.js'></script>
|
||||
<script src='./main.js'></script>
|
||||
</body>
|
||||
</html>
|
170
main.js
Normal file → Executable file
170
main.js
Normal file → Executable file
@ -10,103 +10,139 @@ clipboard.on('success', function(e) {
|
||||
clipboard.on('error', function(e) {
|
||||
$('#copyFeedback').css('display', 'inherit');
|
||||
$('#copyFeedback').css('color', 'red');
|
||||
$('#copyFeedback').html('Failed to copy.');
|
||||
$('#copyFeedback').html('Your browser doesn\'t seem to support automatic copying. Get a better one.');
|
||||
e.clearSelection();
|
||||
});
|
||||
|
||||
if ($('#useEncrypt').is(':checked') == false)
|
||||
{
|
||||
$('#encryptArea').css('display', 'none');
|
||||
}
|
||||
|
||||
$('#modalClose').click(function(){
|
||||
$('#copyFeedback').css('display', 'none');
|
||||
});
|
||||
|
||||
window.snowMode = 'encrypt';
|
||||
window.snowMode = 'encode';
|
||||
|
||||
$("#output").on("click", function () {
|
||||
$(this).select();
|
||||
});
|
||||
|
||||
$('#toggle').click(function(){
|
||||
|
||||
if (window.snowMode == 'encrypt')
|
||||
if (window.snowMode == 'encode')
|
||||
{
|
||||
window.snowMode = 'decrypt';
|
||||
$('#toggle').html("Decrypt Mode");
|
||||
window.snowMode = 'decode';
|
||||
$('#toggle').html("Decode <i class='fa fa-unlock'></i>");
|
||||
$('#confirmPass').css('display', 'none');
|
||||
}
|
||||
else
|
||||
{
|
||||
window.snowMode = 'encrypt';
|
||||
$('#toggle').html("Encrypt Mode");
|
||||
window.snowMode = 'encode';
|
||||
$('#toggle').html("Encode <i class='fa fa-lock'></i>");
|
||||
$('#confirmPass').css('display', 'inline');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* based on stackoverflow.com/questions/14430633/how-to-convert-text-to-binary-code-in-javascript */
|
||||
function binToText(str) {
|
||||
var str = str.replace(/ /g, "1");
|
||||
var str = str.replace(/\t/g, "0");
|
||||
if(str.match(/[10]{8}/g)){
|
||||
var wordFromBinary = str.match(/([10]{8}|\s+)/g).map(function(fromBinary){
|
||||
return String.fromCharCode(parseInt(fromBinary, 2) );
|
||||
}).join('');
|
||||
return wordFromBinary;
|
||||
}
|
||||
}
|
||||
|
||||
/* based on stackoverflow.com/questions/21354235/converting-binary-to-text-using-javascript */
|
||||
function textToBin(text) {
|
||||
var output = '';
|
||||
var length = text.length,
|
||||
output = [];
|
||||
for (var i = 0;i < length; i++) {
|
||||
var bin = text[i].charCodeAt().toString(2);
|
||||
output.push(Array(8-bin.length+1).join("0") + bin);
|
||||
}
|
||||
return output.join('');
|
||||
}
|
||||
|
||||
$('#useEncrypt').click(function(){
|
||||
if (! this.checked)
|
||||
{
|
||||
$('#encryptArea').css('display', 'none');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#encryptArea').css('display', 'inherit');
|
||||
}
|
||||
})
|
||||
|
||||
function verifyPass(mode)
|
||||
{
|
||||
if ($('#password').val() == '')
|
||||
{
|
||||
alert('You must provide a password.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode == 'encrypt')
|
||||
{
|
||||
if ($('#password').val() != $('#confirmPass').val())
|
||||
{
|
||||
alert('Passwords must match.');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$('#go').click(function(){
|
||||
var output = '';
|
||||
|
||||
document.getElementById("go").disabled = true;
|
||||
var input = $('#text').val();
|
||||
|
||||
var password;
|
||||
var confirmPass;
|
||||
var encrypted;
|
||||
var decrypted;
|
||||
var encodeChoice;
|
||||
if (input == '') { return false; }
|
||||
|
||||
var text = $('#text').val();
|
||||
|
||||
if (text == '')
|
||||
// If we're encoding:
|
||||
if (window.snowMode == 'encode')
|
||||
{
|
||||
document.getElementById("go").disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.snowMode == 'encrypt')
|
||||
// If we should use encryption, encrypt first:
|
||||
if ($('#useEncrypt').is(':checked'))
|
||||
{
|
||||
encodeChoice = '1';
|
||||
|
||||
password = $('#password').val();
|
||||
confirmPass = $('#confirmPass').val();
|
||||
|
||||
if (password != confirmPass)
|
||||
// verify password first
|
||||
if (verifyPass('encrypt'))
|
||||
{
|
||||
alert("Passwords must match");
|
||||
document.getElementById("go").disabled = false;
|
||||
return;
|
||||
input = CryptoJS.AES.encrypt(input, $('#password').val()).toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
encrypted = CryptoJS.AES.encrypt(text, password);
|
||||
|
||||
$.post( "./snow2.py", { choice: encodeChoice, text: encrypted.toString()} )
|
||||
.done(function( data ) {
|
||||
document.getElementById("go").disabled = false;
|
||||
|
||||
$('#output').val(data);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// convert result to binary
|
||||
output = textToBin(input);
|
||||
$('#output').val(output.toString().replace(/1/g, " ").replace(/0/g, "\t"));
|
||||
}
|
||||
else
|
||||
{
|
||||
var output = binToText(input);
|
||||
if ($('#useEncrypt').is(':checked'))
|
||||
{
|
||||
if (verifyPass('decrypt'))
|
||||
{
|
||||
output = CryptoJS.AES.decrypt(output, $('#password').val()).toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$('#output').val(output.toString());
|
||||
}
|
||||
$('#outputModal').modal();
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
encodeChoice = '2';
|
||||
|
||||
$.post( "./snow2.py", { choice: encodeChoice, text: text} )
|
||||
.done(function( data ) {
|
||||
|
||||
text = data;
|
||||
password = $('#password').val();
|
||||
|
||||
decrypted = CryptoJS.AES.decrypt(text, password);
|
||||
decrypted = decrypted.toString(CryptoJS.enc.Utf8);
|
||||
if (decrypted == '')
|
||||
{
|
||||
alert('invalid password');
|
||||
document.getElementById("go").disabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById("go").disabled = false;
|
||||
$('#output').val(decrypted);
|
||||
$('#outputModal').modal();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
});
|
1
main.min.js
vendored
1
main.min.js
vendored
@ -1 +0,0 @@
|
||||
var clipboard=new Clipboard(".btn");clipboard.on("success",function(e){$("#copyFeedback").css("display","inherit");$("#copyFeedback").css("color","green");$("#copyFeedback").html("Copied!");e.clearSelection()});clipboard.on("error",function(e){$("#copyFeedback").css("display","inherit");$("#copyFeedback").css("color","red");$("#copyFeedback").html("Failed to copy.");e.clearSelection()});$("#modalClose").click(function(){$("#copyFeedback").css("display","none")});window.snowMode="encrypt";$("#toggle").click(function(){if(window.snowMode=="encrypt"){window.snowMode="decrypt";$("#toggle").html("Decrypt Mode");$("#confirmPass").css("display","none")}else{window.snowMode="encrypt";$("#toggle").html("Encrypt Mode");$("#confirmPass").css("display","inline")}});$("#go").click(function(){document.getElementById("go").disabled=true;var password;var confirmPass;var encrypted;var decrypted;var encodeChoice;var text=$("#text").val();if(text==""){document.getElementById("go").disabled=false;return}if(window.snowMode=="encrypt"){encodeChoice="1";password=$("#password").val();confirmPass=$("#confirmPass").val();if(password!=confirmPass){alert("Passwords must match");document.getElementById("go").disabled=false;return}else{encrypted=CryptoJS.AES.encrypt(text,password);$.post("./snow2.py",{choice:encodeChoice,text:encrypted.toString()}).done(function(data){document.getElementById("go").disabled=false;$("#output").val(data);$("#outputModal").modal()})}}else{encodeChoice="2";$.post("./snow2.py",{choice:encodeChoice,text:text}).done(function(data){text=data;password=$("#password").val();decrypted=CryptoJS.AES.decrypt(text,password);decrypted=decrypted.toString(CryptoJS.enc.Utf8);if(decrypted==""){alert("invalid password");document.getElementById("go").disabled=false}else{document.getElementById("go").disabled=false;$("#output").val(decrypted);$("#outputModal").modal()}})}});
|
40
snow2.py
40
snow2.py
@ -1,40 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import binascii
|
||||
|
||||
import cgi
|
||||
import cgitb; cgitb.enable() # Optional; for debugging only
|
||||
import sys
|
||||
arguments = cgi.FieldStorage()
|
||||
|
||||
# echo headers, additional line-break nessasary.
|
||||
print("content-type: text/plain")
|
||||
print("")
|
||||
|
||||
# get if request is to encode or decode
|
||||
choice = arguments['choice'].value
|
||||
|
||||
if choice == "1":
|
||||
|
||||
# Encode to whitespace
|
||||
|
||||
orig = arguments['text'].value
|
||||
|
||||
binary = bin(int.from_bytes(orig.encode(), 'big'))
|
||||
|
||||
binary = binary.replace("0", " ").replace("1", "\t")
|
||||
|
||||
print(binary[2:])
|
||||
|
||||
elif choice == "2":
|
||||
|
||||
# Decode to the aes text
|
||||
|
||||
binary = " b" + arguments['text'].value
|
||||
|
||||
binary = binary.replace("\t", "1").replace(" ", "0")
|
||||
|
||||
|
||||
n = int(binary, 2)
|
||||
|
||||
print(n.to_bytes((n.bit_length() + 7) // 8, 'big').decode())
|
0
theme.min.css
vendored
Normal file → Executable file
0
theme.min.css
vendored
Normal file → Executable file
Loading…
Reference in New Issue
Block a user