2018-05-23 18:59:57 +01:00
/ * *
* @ author n1474335 [ n1474335 @ gmail . com ]
* @ copyright Crown Copyright 2016
* @ license Apache - 2.0
* /
import Operation from "../Operation" ;
import Utils from "../Utils" ;
2018-11-09 15:25:16 +00:00
import { bitOp , xor , BITWISE _OP _DELIMS } from "../lib/BitwiseOp" ;
2018-05-23 18:59:57 +01:00
/ * *
* XOR operation
* /
class XOR extends Operation {
/ * *
* XOR constructor
* /
constructor ( ) {
super ( ) ;
this . name = "XOR" ;
this . module = "Default" ;
2018-08-24 22:33:24 +01:00
this . description = "XOR the input with the given key.<br>e.g. <code>fe023da5</code><br><br><strong>Options</strong><br><u>Null preserving:</u> If the current byte is 0x00 or the same as the key, skip it.<br><br><u>Scheme:</u><ul><li>Standard - key is unchanged after each round</li><li>Input differential - key is set to the value of the previous unprocessed byte</li><li>Output differential - key is set to the value of the previous processed byte</li><li>Cascade - key is set to the input byte shifted by one</li></ul>" ;
2018-08-21 19:07:13 +01:00
this . infoURL = "https://wikipedia.org/wiki/XOR" ;
2018-05-23 18:59:57 +01:00
this . inputType = "byteArray" ;
this . outputType = "byteArray" ;
this . args = [
{
"name" : "Key" ,
"type" : "toggleString" ,
"value" : "" ,
2018-11-09 15:25:16 +00:00
"toggleValues" : BITWISE _OP _DELIMS
2018-05-23 18:59:57 +01:00
} ,
{
"name" : "Scheme" ,
"type" : "option" ,
2018-08-24 22:33:24 +01:00
"value" : [ "Standard" , "Input differential" , "Output differential" , "Cascade" ]
2018-05-23 18:59:57 +01:00
} ,
{
"name" : "Null preserving" ,
"type" : "boolean" ,
"value" : false
}
] ;
}
/ * *
* @ param { byteArray } input
* @ param { Object [ ] } args
* @ returns { byteArray }
* /
run ( input , args ) {
const key = Utils . convertToByteArray ( args [ 0 ] . string || "" , args [ 0 ] . option ) ,
[ , scheme , nullPreserving ] = args ;
return bitOp ( input , key , xor , nullPreserving , scheme ) ;
}
/ * *
* Highlight XOR
*
* @ param { Object [ ] } pos
* @ param { number } pos [ ] . start
* @ param { number } pos [ ] . end
* @ param { Object [ ] } args
* @ returns { Object [ ] } pos
* /
highlight ( pos , args ) {
return pos ;
}
/ * *
* Highlight XOR in reverse
*
* @ param { Object [ ] } pos
* @ param { number } pos [ ] . start
* @ param { number } pos [ ] . end
* @ param { Object [ ] } args
* @ returns { Object [ ] } pos
* /
highlightReverse ( pos , args ) {
return pos ;
}
}
export default XOR ;