Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.UnsupportedEncodingException;
- import java.util.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Sherlock1 {
- StringBuffer exOR1(StringBuffer s1, StringBuffer s2) {
- StringBuffer s3 = new StringBuffer("");
- for (int i = 0; i < 175; i++) {
- if ((s1.charAt(i) == '0' && s2.charAt(i) == '0')
- || (s1.charAt(i) == '1' && s2.charAt(i) == '1'))
- s3.append("0");
- else
- s3.append("1");
- }
- return s3;
- }
- void showText(StringBuffer s) {
- int m = 0;
- StringBuffer a[] = new StringBuffer[25];
- for (int i = 0; i < s.length(); i += 7) {
- a[m++] = new StringBuffer(s.substring(i, i + 7));
- }
- // System.out.println(Arrays.toString(a));
- int b[] = new int[25];
- for (int j = 0; j < 25; j++) {
- b[j] = Integer.parseInt(new String(a[j]), 2);
- }
- // System.out.println(Arrays.toString(b));
- System.out.println();
- for (int i = 0; i < b.length; i++)
- System.out.print("" + (char) (b[i]));
- }
- StringBuffer convert(StringBuffer s2) throws UnsupportedEncodingException {
- String s1 = new String(s2);
- StringBuffer s3 = new StringBuffer();
- byte[] bytes = s1.getBytes("US-ASCII");
- // System.out.println(Arrays.toString(bytes));
- for (int i = 0; i < bytes.length; i++) {
- s3.append(Integer.toBinaryString(bytes[i]));
- }
- // System.out.println("CONVERT IS :"+s3);
- this.showText(s3);
- return s3;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Sherlock1 sherlock = new Sherlock1();
- StringBuffer s = new StringBuffer(
- "0010101001111100100010001011000000110110010011001000101000011000010110000010000111000000110000100010100100000100001010100000110011010000101100001011001101100101110101011000111");
- // StringBuffer s=new StringBuffer("011010001101110110110");
- // System.out.println(""+s.length());
- StringBuffer r = new StringBuffer(
- "0010001001011000100010001000000110010110010001011001011010010010010111000101100111000010001000111100100110000010001111010011110001110000111100001000001001100101110101011000111");
- // System.out.println(""+s.equals(q));
- // StringBuffer r=new StringBuffer("011010001100010100000");
- // sherlock.convertToText(s);
- System.out.println("ENTER THE SRING");
- StringBuffer s4 = new StringBuffer(sc.next());
- try {
- s4 = sherlock.convert(s4);
- } catch (UnsupportedEncodingException ex) {
- Logger.getLogger(Sherlock1.class.getName()).log(Level.SEVERE, null,
- ex);
- }
- StringBuffer n1 = sherlock.exOR1(r, s);
- StringBuffer n2 = sherlock.exOR1(n1, s4);
- sherlock.showText(n2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment