mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
501 lines
17 KiB
HTML
Executable file
501 lines
17 KiB
HTML
Executable file
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width">
|
|
<title>CyberChef Source: operations/QuotedPrintable.js</title>
|
|
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
|
|
|
|
<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<a class="navbar-brand" href="index.html"><img class="branding-logo" src="../build/prod/images/cyberchef-32x32.png"
|
|
alt="logo"/>CyberChef</a>
|
|
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</button>
|
|
</div>
|
|
<div class="navbar-collapse collapse" id="topNavigation">
|
|
<ul class="nav navbar-nav">
|
|
|
|
<li class="dropdown">
|
|
<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
|
|
<ul class="dropdown-menu inline">
|
|
<li><a href="FlowControl.html">FlowControl</a></li><li><a href="Utils.html">Utils</a></li><li><a href="Base.html">Base</a></li><li><a href="Base64.html">Base64</a></li><li><a href="BitwiseOp.html">BitwiseOp</a></li><li><a href="ByteRepr.html">ByteRepr</a></li><li><a href="CharEnc.html">CharEnc</a></li><li><a href="Checksum.html">Checksum</a></li><li><a href="Cipher.html">Cipher</a></li><li><a href="Code.html">Code</a></li><li><a href="Compress.html">Compress</a></li><li><a href="Convert.html">Convert</a></li><li><a href="DateTime.html">DateTime</a></li><li><a href="Endian.html">Endian</a></li><li><a href="Entropy.html">Entropy</a></li><li><a href="Extract.html">Extract</a></li><li><a href="FileType.html">FileType</a></li><li><a href="HTML.html">HTML</a></li><li><a href="HTTP.html">HTTP</a></li><li><a href="Hash.html">Hash</a></li><li><a href="Hexdump.html">Hexdump</a></li><li><a href="IP.html">IP</a></li><li><a href="JS.html">JS</a></li><li><a href="MAC.html">MAC</a></li><li><a href="Numberwang.html">Numberwang</a></li><li><a href="OS.html">OS</a></li><li><a href="PublicKey.html">PublicKey</a></li><li><a href="Punycode.html">Punycode</a></li><li><a href="QuotedPrintable.html">QuotedPrintable</a></li><li><a href="Rotate.html">Rotate</a></li><li><a href="SeqUtils.html">SeqUtils</a></li><li><a href="StrUtils.html">StrUtils</a></li><li><a href="Tidy.html">Tidy</a></li><li><a href="URL_.html">URL_</a></li><li><a href="UUID.html">UUID</a></li><li><a href="Unicode.html">Unicode</a></li>
|
|
</ul>
|
|
</li>
|
|
|
|
<li class="dropdown">
|
|
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
|
|
<ul class="dropdown-menu inline">
|
|
<li><a href="Chef.html">Chef</a></li><li><a href="Dish.html">Dish</a></li><li><a href="Ingredient.html">Ingredient</a></li><li><a href="Operation.html">Operation</a></li><li><a href="Recipe.html">Recipe</a></li><li><a href="ControlsWaiter.html">ControlsWaiter</a></li><li><a href="HTMLApp.html">HTMLApp</a></li><li><a href="HTMLCategory.html">HTMLCategory</a></li><li><a href="HTMLIngredient.html">HTMLIngredient</a></li><li><a href="HTMLOperation.html">HTMLOperation</a></li><li><a href="HighlighterWaiter.html">HighlighterWaiter</a></li><li><a href="InputWaiter.html">InputWaiter</a></li><li><a href="Manager.html">Manager</a></li><li><a href="OperationsWaiter.html">OperationsWaiter</a></li><li><a href="OptionsWaiter.html">OptionsWaiter</a></li><li><a href="OutputWaiter.html">OutputWaiter</a></li><li><a href="RecipeWaiter.html">RecipeWaiter</a></li><li><a href="SeasonalWaiter.html">SeasonalWaiter</a></li><li><a href="WindowWaiter.html">WindowWaiter</a></li>
|
|
</ul>
|
|
</li>
|
|
|
|
<li class="dropdown">
|
|
<a href="events.list.html" class="dropdown-toggle" data-toggle="dropdown">Events<b class="caret"></b></a>
|
|
<ul class="dropdown-menu inline">
|
|
<li><a href="Manager.html#event:appstart">Manager#event:appstart</a></li><li><a href="Manager.html#event:operationadd">Manager#event:operationadd</a></li><li><a href="Manager.html#event:operationremove">Manager#event:operationremove</a></li><li><a href="Manager.html#event:oplistcreate">Manager#event:oplistcreate</a></li><li><a href="Manager.html#event:statechange">Manager#event:statechange</a></li>
|
|
</ul>
|
|
</li>
|
|
|
|
<li class="dropdown">
|
|
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
|
|
<ul class="dropdown-menu inline">
|
|
<li><a href="global.html#Categories">Categories</a></li><li><a href="global.html#OperationConfig">OperationConfig</a></li><li><a href="global.html#main">main</a></li>
|
|
</ul>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<div class="col-sm-3 col-md-3">
|
|
<form class="navbar-form" role="search">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
|
|
<div class="input-group-btn">
|
|
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="container" id="toc-content">
|
|
<div class="row">
|
|
|
|
|
|
<div class="col-md-12">
|
|
|
|
<div id="main">
|
|
|
|
|
|
<h1 class="page-title">Source: operations/QuotedPrintable.js</h1>
|
|
|
|
<section>
|
|
<article>
|
|
<pre
|
|
class="sunlight-highlight-javascript linenums">/** @license
|
|
========================================================================
|
|
mimelib: http://github.com/andris9/mimelib
|
|
Copyright (c) 2011-2012 Andris Reinman
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
*/
|
|
|
|
/**
|
|
* Quoted Printable operations.
|
|
* Some parts taken from mimelib (http://github.com/andris9/mimelib)
|
|
*
|
|
* @author Andris Reinman
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
* @copyright Crown Copyright 2016
|
|
* @license Apache-2.0
|
|
*
|
|
* @namespace
|
|
*/
|
|
var QuotedPrintable = {
|
|
|
|
/**
|
|
* To Quoted Printable operation.
|
|
*
|
|
* @param {byte_array} input
|
|
* @param {Object[]} args
|
|
* @returns {string}
|
|
*/
|
|
run_to: function (input, args) {
|
|
var mimeEncodedStr = QuotedPrintable.mimeEncode(input);
|
|
|
|
// fix line breaks
|
|
mimeEncodedStr = mimeEncodedStr.replace(/\r?\n|\r/g, function() {
|
|
return "\r\n";
|
|
}).replace(/[\t ]+$/gm, function(spaces) {
|
|
return spaces.replace(/ /g, "=20").replace(/\t/g, "=09");
|
|
});
|
|
|
|
return QuotedPrintable._addSoftLinebreaks(mimeEncodedStr, "qp");
|
|
},
|
|
|
|
|
|
/**
|
|
* From Quoted Printable operation.
|
|
*
|
|
* @param {string} input
|
|
* @param {Object[]} args
|
|
* @returns {byte_array}
|
|
*/
|
|
run_from: function (input, args) {
|
|
var str = input.replace(/\=(?:\r?\n|$)/g, "");
|
|
return QuotedPrintable.mimeDecode(str);
|
|
},
|
|
|
|
|
|
/**
|
|
* Decodes mime-encoded data.
|
|
*
|
|
* @param {string} str
|
|
* @returns {byte_array}
|
|
*/
|
|
mimeDecode: function(str) {
|
|
var encodedBytesCount = (str.match(/\=[\da-fA-F]{2}/g) || []).length,
|
|
bufferLength = str.length - encodedBytesCount * 2,
|
|
chr, hex,
|
|
buffer = new Array(bufferLength),
|
|
bufferPos = 0;
|
|
|
|
for (var i = 0, len = str.length; i < len; i++) {
|
|
chr = str.charAt(i);
|
|
if (chr == "=" && (hex = str.substr(i + 1, 2)) && /[\da-fA-F]{2}/.test(hex)) {
|
|
buffer[bufferPos++] = parseInt(hex, 16);
|
|
i += 2;
|
|
continue;
|
|
}
|
|
buffer[bufferPos++] = chr.charCodeAt(0);
|
|
}
|
|
|
|
return buffer;
|
|
},
|
|
|
|
|
|
/**
|
|
* Encodes mime data.
|
|
*
|
|
* @param {byte_array} buffer
|
|
* @returns {string}
|
|
*/
|
|
mimeEncode: function(buffer) {
|
|
var ranges = [
|
|
[0x09],
|
|
[0x0A],
|
|
[0x0D],
|
|
[0x20],
|
|
[0x21],
|
|
[0x23, 0x3C],
|
|
[0x3E],
|
|
[0x40, 0x5E],
|
|
[0x60, 0x7E]
|
|
],
|
|
result = "";
|
|
|
|
for (var i = 0, len = buffer.length; i < len; i++) {
|
|
if (this._checkRanges(buffer[i], ranges)) {
|
|
result += String.fromCharCode(buffer[i]);
|
|
continue;
|
|
}
|
|
result += "=" + (buffer[i] < 0x10 ? "0" : "") + buffer[i].toString(16).toUpperCase();
|
|
}
|
|
|
|
return result;
|
|
},
|
|
|
|
|
|
/**
|
|
* Checks if a given number falls within a given set of ranges.
|
|
*
|
|
* @private
|
|
* @param {number} nr
|
|
* @param {byte_array[]} ranges
|
|
* @returns {bolean}
|
|
*/
|
|
_checkRanges: function(nr, ranges) {
|
|
for (var i = ranges.length - 1; i >= 0; i--) {
|
|
if (!ranges[i].length)
|
|
continue;
|
|
if (ranges[i].length == 1 && nr == ranges[i][0])
|
|
return true;
|
|
if (ranges[i].length == 2 && nr >= ranges[i][0] && nr <= ranges[i][1])
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
|
|
|
|
/**
|
|
* Adds soft line breaks to a string.
|
|
* Lines can't be longer that 76 + <CR><LF> = 78 bytes
|
|
* http://tools.ietf.org/html/rfc2045#section-6.7
|
|
*
|
|
* @private
|
|
* @param {string} str
|
|
* @param {string} encoding
|
|
* @returns {string}
|
|
*/
|
|
_addSoftLinebreaks: function(str, encoding) {
|
|
var lineLengthMax = 76;
|
|
|
|
encoding = (encoding || "base64").toString().toLowerCase().trim();
|
|
|
|
if (encoding == "qp") {
|
|
return this._addQPSoftLinebreaks(str, lineLengthMax);
|
|
} else {
|
|
return this._addBase64SoftLinebreaks(str, lineLengthMax);
|
|
}
|
|
},
|
|
|
|
|
|
/**
|
|
* Adds soft line breaks to a base64 string.
|
|
*
|
|
* @private
|
|
* @param {string} base64EncodedStr
|
|
* @param {number} lineLengthMax
|
|
* @returns {string}
|
|
*/
|
|
_addBase64SoftLinebreaks: function(base64EncodedStr, lineLengthMax) {
|
|
base64EncodedStr = (base64EncodedStr || "").toString().trim();
|
|
return base64EncodedStr.replace(new RegExp(".{" + lineLengthMax + "}", "g"), "$&\r\n").trim();
|
|
},
|
|
|
|
|
|
/**
|
|
* Adds soft line breaks to a quoted printable string.
|
|
*
|
|
* @private
|
|
* @param {string} mimeEncodedStr
|
|
* @param {number} lineLengthMax
|
|
* @returns {string}
|
|
*/
|
|
_addQPSoftLinebreaks: function(mimeEncodedStr, lineLengthMax) {
|
|
var pos = 0,
|
|
len = mimeEncodedStr.length,
|
|
match, code, line,
|
|
lineMargin = Math.floor(lineLengthMax / 3),
|
|
result = "";
|
|
|
|
// insert soft linebreaks where needed
|
|
while (pos < len) {
|
|
line = mimeEncodedStr.substr(pos, lineLengthMax);
|
|
if ((match = line.match(/\r\n/))) {
|
|
line = line.substr(0, match.index + match[0].length);
|
|
result += line;
|
|
pos += line.length;
|
|
continue;
|
|
}
|
|
|
|
if (line.substr(-1) == "\n") {
|
|
// nothing to change here
|
|
result += line;
|
|
pos += line.length;
|
|
continue;
|
|
} else if ((match = line.substr(-lineMargin).match(/\n.*?$/))) {
|
|
// truncate to nearest line break
|
|
line = line.substr(0, line.length - (match[0].length - 1));
|
|
result += line;
|
|
pos += line.length;
|
|
continue;
|
|
} else if (line.length > lineLengthMax - lineMargin && (match = line.substr(-lineMargin).match(/[ \t\.,!\?][^ \t\.,!\?]*$/))) {
|
|
// truncate to nearest space
|
|
line = line.substr(0, line.length - (match[0].length - 1));
|
|
} else if (line.substr(-1) == "\r") {
|
|
line = line.substr(0, line.length - 1);
|
|
} else {
|
|
if (line.match(/\=[\da-f]{0,2}$/i)) {
|
|
|
|
// push incomplete encoding sequences to the next line
|
|
if ((match = line.match(/\=[\da-f]{0,1}$/i))) {
|
|
line = line.substr(0, line.length - match[0].length);
|
|
}
|
|
|
|
// ensure that utf-8 sequences are not split
|
|
while (line.length > 3 && line.length < len - pos && !line.match(/^(?:=[\da-f]{2}){1,4}$/i) && (match = line.match(/\=[\da-f]{2}$/ig))) {
|
|
code = parseInt(match[0].substr(1, 2), 16);
|
|
if (code < 128) {
|
|
break;
|
|
}
|
|
|
|
line = line.substr(0, line.length - 3);
|
|
|
|
if (code >= 0xC0) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if (pos + line.length < len && line.substr(-1) != "\n") {
|
|
if (line.length == 76 && line.match(/\=[\da-f]{2}$/i)) {
|
|
line = line.substr(0, line.length - 3);
|
|
} else if (line.length == 76) {
|
|
line = line.substr(0, line.length - 1);
|
|
}
|
|
pos += line.length;
|
|
line += "=\r\n";
|
|
} else {
|
|
pos += line.length;
|
|
}
|
|
|
|
result += line;
|
|
}
|
|
|
|
return result;
|
|
},
|
|
|
|
};
|
|
</pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="clearfix"></div>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="modal fade" id="searchResults">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
|
<h4 class="modal-title">Search results</h4>
|
|
</div>
|
|
<div class="modal-body"></div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
|
</div>
|
|
</div><!-- /.modal-content -->
|
|
</div><!-- /.modal-dialog -->
|
|
</div>
|
|
|
|
|
|
<footer>
|
|
|
|
|
|
<span class="copyright">
|
|
© Crown Copyright 2016
|
|
</span>
|
|
|
|
<span class="jsdoc-message">
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>
|
|
|
|
on Mon Nov 28th 2016
|
|
|
|
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
|
|
</span>
|
|
</footer>
|
|
|
|
<script src="scripts/docstrap.lib.js"></script>
|
|
<script src="scripts/toc.js"></script>
|
|
|
|
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
|
|
|
|
|
|
<script>
|
|
$( function () {
|
|
$( "[id*='$']" ).each( function () {
|
|
var $this = $( this );
|
|
|
|
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
|
|
} );
|
|
|
|
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
|
|
var $this = $( this );
|
|
|
|
var example = $this.find( "code" );
|
|
exampleText = example.html();
|
|
var lang = /{@lang (.*?)}/.exec( exampleText );
|
|
if ( lang && lang[1] ) {
|
|
exampleText = exampleText.replace( lang[0], "" );
|
|
example.html( exampleText );
|
|
lang = lang[1];
|
|
} else {
|
|
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
|
|
lang = langClassMatch ? langClassMatch[1] : "javascript";
|
|
}
|
|
|
|
if ( lang ) {
|
|
|
|
$this
|
|
.addClass( "sunlight-highlight-" + lang )
|
|
.addClass( "linenums" )
|
|
.html( example.html() );
|
|
|
|
}
|
|
} );
|
|
|
|
Sunlight.highlightAll( {
|
|
lineNumbers : true,
|
|
showMenu : true,
|
|
enableDoclinks : true
|
|
} );
|
|
|
|
$.catchAnchorLinks( {
|
|
navbarOffset: 10
|
|
} );
|
|
$( "#toc" ).toc( {
|
|
anchorName : function ( i, heading, prefix ) {
|
|
return $( heading ).attr( "id" ) || ( prefix + i );
|
|
},
|
|
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
|
|
showAndHide : false,
|
|
smoothScrolling: true
|
|
} );
|
|
|
|
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
|
|
$( '.dropdown-toggle' ).dropdown();
|
|
|
|
$( "table" ).each( function () {
|
|
var $this = $( this );
|
|
$this.addClass('table');
|
|
} );
|
|
|
|
} );
|
|
</script>
|
|
|
|
|
|
|
|
<!--Navigation and Symbol Display-->
|
|
|
|
|
|
<!--Google Analytics-->
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
$(document).ready(function() {
|
|
SearcherDisplay.init();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html>
|