Martin Paul Eve bio photo

Martin Paul Eve

Professor of Literature, Technology and Publishing at Birkbeck, University of London

Email Books Twitter Github Stackoverflow MLA CORE Institutional Repo Hypothes.is ORCID ID  ORCID iD Wikipedia Pictures for Re-Use

Here is a nice tool for encoding JavaScript into eval(String.fromCharCode(x,x,x)) format. A full HTML page is listed here, or you can try it out live at the bottom of this post.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Javascript Eval Encoder</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
	<script type="text/javascript">
		function encode_to_javascript() {
			var input = document.getElementById('inputtext').value;

			var output = 'eval(String.fromCharCode(';

			for(pos = 0; pos < input.length; pos++) {
				output += input.charCodeAt(pos);
	
				if(pos != (input.length - 1)) {
					output += ",";
				}
			}

			output += '))';

			document.getElementById('result').innerHTML = output;
			return 0;
		}
	</script>
	</head>
	<body>
		<textarea id="inputtext" rows="10" cols="50"></textarea><br/>
		<input type="submit" value="Encode" onclick="javascript:encode_to_javascript()"/>
		<br/><span id="result"></span>
	</body>
</html>

Encode