Statistics

Problem Statement for "PassRoaster"

Problem Statement

PROBLEM STATEMENT

One incredibly weak way of encoding passwords is called Password Roasting.

To roast a password, a Roasting String is needed.  Roasting is performed by
first xoring each character in the password with the equivalent modulo
character in the roasting string.  The result of each xor is then converted to
ascii hex (two digits, so the decimal value 10 goes to the hex value 0a).  The
2 digit hex values are then all combined (in the same order as their
corresponding characters in the password string) and the result is prepended
with "0x" (That is the numerical digit '0' followed by the lowercase letter
'x').  The modulo character in the roasting string of the character at index i
in the password is the character at index i mod <length-of-roasting-string>
(assuming the string indices are 0 based).

You are to create a class PassRoaster which contains a method roast that takes
a password and a roasting string and returns the encoded password.

DEFINITION
Class: PassRoaster
Method: roast
Parameters: String, String
Returns: String
Method Signature (be sure your method is public): String roast(String password,
String roastingString);

TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
* password will have length between 1 and 50 inclusive.
* roastingString will have length between 1 and 50 inclusive.
* password and roastingString will contain capital and lowercase letters only
(a-z, A-Z).

NOTES
* Use lower case 'a' - 'f', inclusive, to represent the hex values of 10 
   - 15, inclusive ('a' for 10, 'b' for 11, etc..)
* When xoring characters, xor the ASCII values, and assume all but the seven
  least significant bits are 0.
* The xoring is bitwise.  That is convert the integer value of the character
  to binary and xor each bit. The results of xoring are: 
    0 xor 0 = 0
    0 xor 1 = 1
    1 xor 0 = 1
    1 xor 1 = 0
* The decimal ASCII values of 'a' - 'z' are 97 - 122, respectively, and the 
  values of 'A' - 'Z' are 65 - 90, respectively.

EXAMPLES

1)
password: "password" 
roastingString: "tictoc"

returns: "0x04081007180c060d"

The following xor's are done:
p=01110000 t=01110100  xor = 00000100 hex = 04
a=01100001 i=01101001  xor = 00001000 hex = 08
s=01110011 c=01100011  xor = 00010000 hex = 10
s=01110011 t=01110100  xor = 00000111 hex = 07
w=01110111 o=01101111  xor = 00011000 hex = 18
o=01101111 c=01100011  xor = 00001100 hex = 0c
r=01110010 t=01110100  xor = 00000110 hex = 06
d=01100100 i=01101001  xor = 00001101 hex = 0d
So the method returns "0x04081007180c060d"

2)
password: "password"
roastingString: "TicToc"

returns: "0x24081027180c260d"

3)
password: "topcoderisgreat"
roastingString: "s" 

returns: "0x071c03101c1716011a001401161207"

4)
password: "hello"
roastingString: "hello" 

returns: "0x0000000000"

5)
password: "a"
roastringString: "reallylongroastingstringdoesntmatter" 

returns: "0x13"

6)
password: "LETSTRYSOMECAPS"
roastingString: "aLtErNaTe" 

returns: "0x2d092016261c38072a2c093704221d"

Definition

Class:
PassRoaster
Method:
roast
Parameters:
String, String
Returns:
String
Method signature:
String roast(String param0, String param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: