<commit_before>function encrypt() {
  return {
    then: function(callback) {
			
	var message_body_input = $('#message_body_input').val();
	$("#message_body_input").attr("disabled", "disabled");
	if (message_body_input.indexOf("-----BEGIN PGP MESSAGE-----") !== -1 && message_body_input.indexOf("-----END PGP MESSAGE-----") !== -1) {
		callback(true);	
	} else {
		// encrypt message
		publicKeys = openpgp.key.readArmored($('#pubkey').text()).keys[0];
		var validatePublicKeys = JSON.stringify(publicKeys).replace(/,/g,'\n');
		$('#check-pubkey').text(validatePublicKeys);

   	var message = document.getElementById("message_body_input");
		
   	var plaintext = message.value;
   	openpgp.encryptMessage([publicKeys],plaintext).then(function(ciphertext) {
			var result = openpgp.message.readArmored(ciphertext);
			var validateMessage = JSON.stringify(result).replace(/,/g,'\n');
			$('#check-message').text(validateMessage);

	   	message.value = ciphertext;	
			var message_body = document.getElementById("message_body");
			message_body.value = ciphertext;
			callback(true);	

   	});
	}
			
  }
};
}

function file() {	
	// encrypt file		
	var file = $("#message_file_input").get(0).files[0];
	
	if (file.size > 1048576) {
		alert("Sorry file size > 1 MB!");
		$("#message_file_input").val("");
		return
	}
	
	$("#message_file_input").hide();
	$("#encrypting").text("Encrypting...");
	$("#encrypting").show();
	
  var reader = new FileReader();
  reader.onload = function(e) {
  	var msg = openpgp.message.fromBinary(e.target.result);
		publicKeys = openpgp.key.readArmored($('#pubkey').text()).keys[0];
		msg = msg.encrypt([publicKeys]);
		var armored = openpgp.armor.encode(openpgp.enums.armor.message, msg.packets.write());
		var message_file = document.getElementById("message_file");
		message_file.value = window.btoa(armored);
		var message_filename = document.getElementById("message_filename");
		message_filename.value = file.name + ".gpg"
		$("#encrypting").text(file.name + ".gpg encrypted.");
		$('#remove').show();
  }
  reader.readAsBinaryString(file);
	
}

function fingerprint(key) {
	var fpr = key.primaryKey.getFingerprint().toUpperCase();
  return "Fingerprint: " + fpr.slice(0, 4) + ' ' + fpr.slice(4, 8) + ' ' + fpr.slice(8, 12) + ' ' + fpr.slice(12, 16) + ' ' + fpr.slice(16, 20) + ' ' + fpr.slice(20, 24) + ' ' + fpr.slice(24, 28) + ' ' + fpr.slice(28, 32) + ' ' + fpr.slice(32, 36) + ' ' + fpr.slice(36);
}

function validateEmail($email) {
  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  if (!emailReg.test($email)) {
    return false;
  } else {
    return true;
  }
}

$(function(){
	
	// prevent form submit by enter
	$("#new_message").bind("keypress", function (e) {
	    if (e.keyCode == 13) {
	        return false;
	    }
	});
	
	// init openpgp worker
	openpgp.initWorker('/assets/openpgp.worker.min.js');
	
	// focus body on load
   $("#message_body_input").focus();
	 
	 // show fingerprint
	 var fp = fingerprint(openpgp.key.readArmored($('#pubkey').text()).keys[0]);
	 $("#fingerprint").text(fp);
   
	if (window.crypto && window.crypto.getRandomValues) {
	    // ready
		 } else {
	  	$('.marker_browser').show();
			$('#send').hide();
		}

   // advanced mode
   $('#advanced').change(function(){
       if($(this).is(':checked')){<commit_msg>prevent form submit by enter<commit_after>function encrypt() {
  return {
    then: function(callback) {
			
	var message_body_input = $('#message_body_input').val();
	$("#message_body_input").attr("disabled", "disabled");
	if (message_body_input.indexOf("-----BEGIN PGP MESSAGE-----") !== -1 && message_body_input.indexOf("-----END PGP MESSAGE-----") !== -1) {
		callback(true);	
	} else {
		// encrypt message
		publicKeys = openpgp.key.readArmored($('#pubkey').text()).keys[0];
		var validatePublicKeys = JSON.stringify(publicKeys).replace(/,/g,'\n');
		$('#check-pubkey').text(validatePublicKeys);

   	var message = document.getElementById("message_body_input");
		
   	var plaintext = message.value;
   	openpgp.encryptMessage([publicKeys],plaintext).then(function(ciphertext) {
			var result = openpgp.message.readArmored(ciphertext);
			var validateMessage = JSON.stringify(result).replace(/,/g,'\n');
			$('#check-message').text(validateMessage);

	   	message.value = ciphertext;	
			var message_body = document.getElementById("message_body");
			message_body.value = ciphertext;
			callback(true);	

   	});
	}
			
  }
};
}


function file() {	
	// encrypt file		
	var file = $("#message_file_input").get(0).files[0];
	
	if (file.size > 1048576) {
		alert("Sorry file size > 1 MB!");
		$("#message_file_input").val("");
		return
	}
	
	$("#message_file_input").hide();
	$("#encrypting").text("Encrypting...");
	$("#encrypting").show();
	
  var reader = new FileReader();
  reader.onload = function(e) {
  	var msg = openpgp.message.fromBinary(e.target.result);
		publicKeys = openpgp.key.readArmored($('#pubkey').text()).keys[0];
		msg = msg.encrypt([publicKeys]);
		var armored = openpgp.armor.encode(openpgp.enums.armor.message, msg.packets.write());
		var message_file = document.getElementById("message_file");
		console.log(armored);
		message_file.value = window.btoa(armored);
		var message_filename = document.getElementById("message_filename");
		message_filename.value = file.name + ".gpg"
		$("#encrypting").text(file.name + ".gpg encrypted.");
		$('#remove').show();
  }
  reader.readAsBinaryString(file);
	
}

function fingerprint(key) {
	var fpr = key.primaryKey.getFingerprint().toUpperCase();
  return "Fingerprint: " + fpr.slice(0, 4) + ' ' + fpr.slice(4, 8) + ' ' + fpr.slice(8, 12) + ' ' + fpr.slice(12, 16) + ' ' + fpr.slice(16, 20) + ' ' + fpr.slice(20, 24) + ' ' + fpr.slice(24, 28) + ' ' + fpr.slice(28, 32) + ' ' + fpr.slice(32, 36) + ' ' + fpr.slice(36);
}

function validateEmail($email) {
  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  if (!emailReg.test($email)) {
    return false;
  } else {
    return true;
  }
}

$(function(){
	
	// prevent form submit by enter
	$('input,select').bind("keypress", function (e) {
	    if (e.keyCode == 13) {
	        return false;
	    }
	});
	
	// init openpgp worker
	openpgp.initWorker('/assets/openpgp.worker.min.js');
	
	// focus body on load
   $("#message_body_input").focus();
	 
	 // show fingerprint
	 var fp = fingerprint(openpgp.key.readArmored($('#pubkey').text()).keys[0]);
	 $("#fingerprint").text(fp);
   
	if (window.crypto && window.crypto.getRandomValues) {
	    // ready
		 } else {
	  	$('.marker_browser').show();
			$('#send').hide();
		}

   // advanced mode
   $('#advanced').change(function(){
       if($(this).is(':checked')){
{'fraction_non_alphanumeric': 0.20957542908762422, 'fraction_numerical': 0.015657934357121348, 'mean_word_length': 3.813768115942029, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6479571', 'n_tokens_mistral': 2509, 'n_tokens_neox': 2297, 'n_words': 368}