2018-04-03 23:50:26 +02:00
/ * *
* @ author Matt C [ matt @ artemisbot . uk ]
* @ copyright Crown Copyright 2016
* @ license Apache - 2.0
* /
2019-07-09 13:23:59 +02:00
import Operation from "../Operation.mjs" ;
2018-04-03 23:50:26 +02:00
/ * *
* ROT47 operation .
* /
class ROT47 extends Operation {
/ * *
* ROT47 constructor
* /
constructor ( ) {
super ( ) ;
this . name = "ROT47" ;
this . module = "Default" ;
this . description = "A slightly more complex variation of a caesar cipher, which includes ASCII characters from 33 '!' to 126 '~'. Default rotation: 47." ;
2018-08-21 20:07:13 +02:00
this . infoURL = "https://wikipedia.org/wiki/ROT13#Variants" ;
2018-04-03 23:50:26 +02:00
this . inputType = "byteArray" ;
this . outputType = "byteArray" ;
this . args = [
{
name : "Amount" ,
type : "number" ,
2018-04-06 14:40:39 +02:00
value : 47
2018-04-03 23:50:26 +02:00
} ,
] ;
}
/ * *
2018-04-06 14:40:39 +02:00
* @ param { byteArray } input
2018-04-03 23:50:26 +02:00
* @ param { Object [ ] } args
* @ returns { byteArray }
* /
run ( input , args ) {
const output = input ;
let amount = args [ 0 ] ,
chr ;
if ( amount ) {
if ( amount < 0 ) {
amount = 94 - ( Math . abs ( amount ) % 94 ) ;
}
for ( let i = 0 ; i < input . length ; i ++ ) {
chr = input [ i ] ;
if ( chr >= 33 && chr <= 126 ) {
chr = ( chr - 33 + amount ) % 94 ;
output [ i ] = chr + 33 ;
}
}
}
return output ;
}
/ * *
* Highlight ROT47
*
* @ param { Object [ ] } pos
* @ param { number } pos [ ] . start
* @ param { number } pos [ ] . end
* @ param { Object [ ] } args
* @ returns { Object [ ] } pos
* /
highlight ( pos , args ) {
return pos ;
}
/ * *
* Highlight ROT47 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 ROT47 ;