Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with xor'ing 2 strings and printing the xor result. I have code that converts the String into a BigInt then xor them then

Need help with xor'ing 2 strings and printing the xor result. I have code that converts the String into a BigInt then xor them then converts the BigInt back into String, but it is not working well. Can someone help to fix my code please?

public static void main(String[] arguments) { String cipherText6 = "9a6972380c5a91e5f80537193ca133c7e75faea9924bb191953e8f22d7c5adf067264b1d96f853c41892ad4480bd73f54902b1af35ef1860ac02972d05013543d93d306603fb4932be8b3d8f4825613183571320c170d9cde638f41e80e173e3dc5caefb574d6fce688cc49113f515a6cf7f2c066e4c3385230885884ddcf3f898029fe1e8dd3fcc9f76f3a77d35fa2d75b281b7e56b7f45bf3225e3ff003501d78d146e018e484ee18383d187ca0d6025d5f348ed9b61ae7f33acbfddf36b774d60a86ca016d1f4c83b8dbdaf59795e624dbdbbf310a5b271813fa31400835f4eec250ddd43de10a25e790c9f28e7ebd0c74fa11181fcf79cf68d5bd75b662bbacf38d31b39cbcdc71d213d611812188ebe8855dcf857337ac75e2b36cceb0c4a729e1b7c72e78e0962c112351e62aa0f41456ebd34667929cdb06c2ffd627d7b11da0b6dd57900d0cafd9651a32e8d4247a7ab3cce24d08150ceee321b38dae50481acf00896ce1f8c7b7499dcf79008c9b5aee24b8de4ff1737116c"; String cipherText3 = "8f6f3779154f99e8e014375c34a267c1e745bbad895fe391c526873383cfa1e86632575481e803c41c93f94d97a738f54d02a9ec66bb1360b44ed3210206254fcc627b240bfb1d38b899788a093d2f2a9b4b1327c17edf99b224fe1e9ee66effc649a3b5430c7c9a2a91d7c51bab14e9d57d39566a5634c4340c858c5a93fff89e0394f3f49369ce9c6ee6f26b29a82e29fb9ca0a8657c48ad2c60eaf70a6b44918a40630392171ca29b87cd9e9e037c6ad2bc4be08c61ba6223a8bac0a024741b71b270a0579ab1d0308ce9b54b391a6a49ebacfc5eb5b57dd56caf0b1694544cfa6e"; BigInteger c6, c3, result; String xorResult; c6 = convertStringToBigInt(cipherText6); c3 = convertStringToBigInt(cipherText3); result = c6.xor(c3); xorResult = convertBigIntToString(result); System.out.println(xorResult);

}

public static BigInteger convertStringToBigInt(String s) { BigInteger b = new BigInteger("0"); for(int i = 0; i < s.length(); i++) { Integer code = new Integer((int)s.charAt(i)); BigInteger c = new BigInteger(code.toString()); b = b.shiftLeft(8); b = b.or(c); } return b; } public static String convertBigIntToString(BigInteger b) { String s = new String(); while(b.compareTo(BigInteger.ZERO) == 1) { BigInteger c = new BigInteger("11111111", 2); int cb = (b.and(c)).intValue(); Character cv = new Character((char)cb); s = (cv.toString()).concat(s); b = b.shiftRight(8); } return s; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Influxdb Database A Comprehensive Guide To Learn Influxdb Database

Authors: Cybellium Ltd ,Kris Hermans

1st Edition

B0CNGGWL7B, 979-8867766450

More Books

Students also viewed these Databases questions

Question

How is sensitivity analysis used in project selection?

Answered: 1 week ago

Question

Network demand will not be reduced by

Answered: 1 week ago