I have to perform a XOR operation on the two strings, I got the python implementation of it:
def sxor(s1,s2):
return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2))
In the above code , we are running the for loop on the strings and we are creating the tuples of it.
string 1: abcdefghijklmn
string 2: 12345
it will create the tuples out of it
[('a','1'),('b','2'),('c','3'),('d','4'),('e','5')]
we have to perform the xor operation on this tuples
chr(ord('a')^ord('1')) which will result => p
chr(ord('b')^ord('2')) which will result => p
chr(ord('c')^ord('3')) which will result => p
chr(ord('d')^ord('4')) which will result => p
chr(ord('e')^ord('5')) which will result => p
I want output as ppppp
.
I want to implement the same algorithm in angular
I have done this
export class AppComponent implements OnInit {
name = 'Angular ' + VERSION.major;
array1 = [1, 7, 8, 8, 7];
array2 = ['r', 'u', 'm', 'a', 'n'];
zip: any;
ordValue: any;
value: any;
ngOnInit(): void {
this.ordValue = this.ord('r') ^ this.ord('1');
console.log(this.ordValue);
this.value = String.fromCharCode(this.ordValue);
console.log('ASCII ' + this.value);
}
ord(str) {
return str.charCodeAt(0);
}
}
which is giving the character after XOR
stackblitz Demo : stackblitz