Minecraft PC IP: play.cubecraft.net
Status
Not open for further replies.

xRabbitGaming

Novice Member
Dec 9, 2017
180
237
44
23
Not where I want to be
xrabbitgaming.com
Okay so I have a challenge for you Java programmers out there;

Code:
package com.xrabbitgaming.tryme;

public class Main
{
    static int kl = 9001;

    public static void main(String[] args)
    {
        if (args.length == 1)
        {
            int sum = 0;
            for (int i = 0; i < args[0].length(); i++)
                sum += (int) args[0].charAt(i);

            if (sum == kl)
                System.out.println("Correct key! Now write me a key generator for it.");
            else
                System.out.println("Wrong key! I'm sure you tried your best.");
        }
        else
        {
            System.out.println("You should probably input your key as an argument.");
        }
        System.exit(0);
    }
}

Try finding out the correct key and write a key generator for it. Sorry if this is expert-level stuff. ;)
Please use the spoiler bbcode.

I'll be trying to make more challenges like this and give people points based on how they do / explain how they managed to get the correct key.

Jar download: https://www112.zippyshare.com/v/oVE1lm8x/file.html
You can run this with: java -jar TryMe.jar YOUR_KEY

Note: you cannot change the kl variable, that would be considered cheating.

Points:
@MagnificentSpam - 10 (+5 for using a different language)
 
Last edited:

MagnificentSpam

Forum Expert
Mar 16, 2016
2,306
2,239
298
Not the most efficient code but it does spit out keys:
Code:
import sys, random

with open('/usr/share/dict/words') as f:
    l = f.readlines()

def generater(goal):
    res = ''
    val = 0
    t = 50
    while val < goal:
        w = random.choice(l).strip()
        wval = sum(ord(c) for c in w)
        if val + wval > goal:
            if t > 0:
                t -= 1
                continue
            w = ''
            while goal - val > 48:
                c = random.randint(48, min(120, goal - val))
                val += c
                w += chr(c)
            if val < goal:
                return generater(goal)
        res += w
        val += wval
    return res

print(generater(int(sys.argv[1])))

Edit:
Code:
$ for i in $(seq 10); do key=$(python gen.py 9001); echo "trying key: $key"; java -jar TryMe.jar "$key"; done
trying key: bpsscallionsinvestigatordishonourablyHallie'shandholdsshirker'sbreakoutscommiseration
Correct key! Now write me a key generator for it.
trying key: Zanzibar'sapothegmsracquetballacademiespalsydepoliticisedplumbsHubbardshandyleveringOR
Correct key! Now write me a key generator for it.
trying key: collectmunicipalitypreregisterGambiansbeer'sartlessnesspilgrimagesdearerAtaturk'shims@
Correct key! Now write me a key generator for it.
trying key: qualmcommandsfranchisingmotorcade'sGilligan'setiologiclikeness'sBuddhist'senvisageSSTtuU
Correct key! Now write me a key generator for it.
trying key: snifferuptickTell'sodiouslyGaul'ssoulbathyscaphfundraiser'srafflingdivinedumboblearyIL<
Correct key! Now write me a key generator for it.
trying key: geochemistry'sMinutemanpardoner'spostulate'sblenderpanamasworthlesslyNYCslotsmediating
Correct key! Now write me a key generator for it.
trying key: importuneddoormatsGena'sBoswell'stradespeople'sembolismsmillagenasalisingYaquiEdgar'su@F
Correct key! Now write me a key generator for it.
trying key: potluckroughhousingsunbeamXLwarblecauliflowerspsalmistTimurhumbugskydivedmasonicblag
Correct key! Now write me a key generator for it.
trying key: slimming'spealsreinspectingcrystallization'ssullensimianDebian'sequivocallyscoutsJuddB
Correct key! Now write me a key generator for it.
trying key: Falkland'sprobe'sMillarddewberry'sreinspectmonologuesimpecuniousclubbersperforations2d3
Correct key! Now write me a key generator for it.
 
  • Like
Reactions: xRabbitGaming

xRabbitGaming

Novice Member
Dec 9, 2017
180
237
44
23
Not where I want to be
xrabbitgaming.com
Not the most efficient code but it does spit out keys:
Code:
import sys, random

with open('/usr/share/dict/words') as f:
    l = f.readlines()

def generater(goal):
    res = ''
    val = 0
    t = 50
    while val < goal:
        w = random.choice(l).strip()
        wval = sum(ord(c) for c in w)
        if val + wval > goal:
            if t > 0:
                t -= 1
                continue
            w = ''
            while goal - val > 48:
                c = random.randint(48, min(120, goal - val))
                val += c
                w += chr(c)
            if val < goal:
                return generater(goal)
        res += w
        val += wval
    return res

print(generater(int(sys.argv[1])))

Edit:
Code:
$ for i in $(seq 10); do key=$(python gen.py 9001); echo "trying key: $key"; java -jar TryMe.jar "$key"; done
trying key: bpsscallionsinvestigatordishonourablyHallie'shandholdsshirker'sbreakoutscommiseration
Correct key! Now write me a key generator for it.
trying key: Zanzibar'sapothegmsracquetballacademiespalsydepoliticisedplumbsHubbardshandyleveringOR
Correct key! Now write me a key generator for it.
trying key: collectmunicipalitypreregisterGambiansbeer'sartlessnesspilgrimagesdearerAtaturk'shims@
Correct key! Now write me a key generator for it.
trying key: qualmcommandsfranchisingmotorcade'sGilligan'setiologiclikeness'sBuddhist'senvisageSSTtuU
Correct key! Now write me a key generator for it.
trying key: snifferuptickTell'sodiouslyGaul'ssoulbathyscaphfundraiser'srafflingdivinedumboblearyIL<
Correct key! Now write me a key generator for it.
trying key: geochemistry'sMinutemanpardoner'spostulate'sblenderpanamasworthlesslyNYCslotsmediating
Correct key! Now write me a key generator for it.
trying key: importuneddoormatsGena'sBoswell'stradespeople'sembolismsmillagenasalisingYaquiEdgar'su@F
Correct key! Now write me a key generator for it.
trying key: potluckroughhousingsunbeamXLwarblecauliflowerspsalmistTimurhumbugskydivedmasonicblag
Correct key! Now write me a key generator for it.
trying key: slimming'spealsreinspectingcrystallization'ssullensimianDebian'sequivocallyscoutsJuddB
Correct key! Now write me a key generator for it.
trying key: Falkland'sprobe'sMillarddewberry'sreinspectmonologuesimpecuniousclubbersperforations2d3
Correct key! Now write me a key generator for it.

Whahaha nice job, do you understand the logic behind it? Also extra points for using a different language :P
Gg.
 

CodeOfDark

Member
Nov 7, 2017
20
41
29
33
Ehh, you should a bit try to obfuscate the code xD like easily you can just write "System.out.println(kl);" to get the Key or just get the operand of Field "kl" 9001 xD

Nice
 
  • Like
Reactions: xRabbitGaming

CodeOfDark

Member
Nov 7, 2017
20
41
29
33
private void Form1_Load(object sender, EventArgs e)
{
int kl = 9001;
string[] args = { KeyGenerator(kl) };
int sum = 0;
for (int i = 0; i < args[0].Length; i++)
sum += (int)args[0];
if (sum == kl)
MessageBox.Show("Correct key! Now write me a key generator for it.");
else
MessageBox.Show("Wrong key! I'm sure you tried your best.");
}
public static string KeyGenerator(int value)
{
StringBuilder strB = new StringBuilder();
int result = 0;
while (true)
{
int a = ((value - (value - new Random(Guid.NewGuid().GetHashCode()).Next(1, 90))));
if ((result + a) > value)
{
int kk = 0;
for (int ib = result; ib < value; ib++)
kk += 1;
strB.Append(Convert.ToChar(kk).ToString());
return strB.ToString();
}
else
{
result += a;
strB.Append(Convert.ToChar(a).ToString());
}
}

}
 

werra11

Dedicated Member
Jan 8, 2016
460
648
168
22
Friesland, The Netherlands.
www.werra11.eu
szXn25L.gif
 

Max ♠

Forum Expert
Feb 20, 2016
1,420
2,940
344
24
North pole
Code:
/*

    Too lazy to write my own function for RNG
    https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range#1527820

*/

function getRandomArbitrary(min, max) {
    return Math.random() * (max - min) + min;
}

/*

    Code below is written by me

*/

var goal = process.argv[2];

/*

    Added a range to make it more interesting than returning the character associated with code point 9001

*/

var range = {
    "min" : 33,
    "max" : 126 // Make sure max is more than twice as high as min for it to work properly
};

var string = {
    "str" : "",
    "val" : 0
};

function required_amount() {
    return goal - string["val"];
}

function addCharacter(char) {
    string["str"] += String.fromCodePoint(char);
    string["val"] += char;
}

do {
    if(required_amount() <= range["max"]) {
        addCharacter(required_amount());
        break;
    }
 
    if(Math.ceil(required_amount() / 2) <= range["max"]) {
        addCharacter(Math.ceil(required_amount() / 2));
        continue;
    }
 
    addCharacter(Math.round(getRandomArbitrary(range["min"], range["max"])));
} while(string["val"] < goal);

console.log(string);

For those who want to perform the keychecks in javascript
Code:
var string = process.argv[2];

if(string == undefined)
    process.exit(1);

var res = 0;
var goal = 9001;

for(var i = 0; i < string.length; i++)
    res += string.codePointAt(i);

if(res == goal)
    console.log("Goal reached");
else
    console.log("Nope, " + res);

/*

Use "node [filename] [key]" to run or hardcode the value as string(line 1)

*/
I was having trouble escaping characters in command line so I made this as so I wouldn't have to mess around with java to hardcode the string to check
 
  • Like
Reactions: werra11

Priley

Forum Professional
Jul 6, 2015
4,119
16,204
679
21
reprotland
Okay so I have a challenge for you Java programmers out there;

Code:
package com.xrabbitgaming.tryme;

public class Main
{
    static int kl = 9001;

    public static void main(String[] args)
    {
        if (args.length == 1)
        {
            int sum = 0;
            for (int i = 0; i < args[0].length(); i++)
                sum += (int) args[0].charAt(i);

            if (sum == kl)
                System.out.println("Correct key! Now write me a key generator for it.");
            else
                System.out.println("Wrong key! I'm sure you tried your best.");
        }
        else
        {
            System.out.println("You should probably input your key as an argument.");
        }
        System.exit(0);
    }
}

Try finding out the correct key and write a key generator for it. Sorry if this is expert-level stuff. ;)
Please use the spoiler bbcode.

I'll be trying to make more challenges like this and give people points based on how they do / explain how they managed to get the correct key.

Jar download: https://www112.zippyshare.com/v/oVE1lm8x/file.html
You can run this with: java -jar TryMe.jar YOUR_KEY

Note: you cannot change the kl variable, that would be considered cheating.

Points:
@MagnificentSpam - 10 (+5 for using a different language)
Glad this person got banned
 
Last edited:
Status
Not open for further replies.
Members Online

Team online

Latest profile posts

NADER KANAAN wrote on jamesthesignificant's profile.
ty for the following !!!
jamesthesignificant wrote on NADER KANAAN's profile.
have a totally epic birthday!!! 🎈
IAmEclipsy wrote on CalvinxKlein's profile.
Happy birthday!
CrystalLegend01 wrote on NADER KANAAN's profile.
Happy Birthday!
coolzombiee wrote on NADER KANAAN's profile.
Happy birthday!
Top Bottom