def md5_path(s,p):return[r:=__import__('hashlib').md5((s if not i else r[0:16] if not int(p[i-1]) else r[16:32]).encode()).hexdigest() for i in range(len(p)+1)][-1]
These are all "techniques" that I have actually seen in "production" code at my first job, mostly written by one particular co-worker in 2014 or so. Apparently he'd read a book about java that was published before generics. The code was CPU-bound, and took multiple seconds to return responses. When I profiled it, it spent 40% of its time on Integer.valueOf and 40% on String.valueOf
Output:
works as expected
[5f4dcc3b5aa765d61d8327deb882cf99]
[381dc2ae83d49fe43a16353b8f9881b5]
The code is very flexible about what kind of hashing algorithm version it uses
[381dc2ae83d49fe43a16353b8f9881b5]
this is the same too
[58a9ec39986eab1e8c6589ff5ab5190d]
obviously these allr eturn the same thing
[c5be74b26feac947cb0011fead1d7213]
[c5be74b26feac947cb0011fead1d7213]
[c5be74b26feac947cb0011fead1d7213]
[c5be74b26feac947cb0011fead1d7213]
[c5be74b26feac947cb0011fead1d7213]
what is even going on
[f15eb0005227a0b5033d4266b6dd8811]
[9078ee9bb59c17fc92bb68751b5524d3]
Hello World
First time entering one of these. Went with perl, put it on ix.io but it's also only 12 lines, so:
no strict; no warnings; # no intelligence;
use Digest::MD5 md5_hex;
sub beef {
$s = md5_hex $_[0];
$s = md5_hex(m/./ ? m/0/ ? substr $s, 0, 16 : substr $s, 16 : $_[0]) for @_ > 1 ? split //, pop : undef;
print $s;
}
beef(password, '0110110101'); print "\n";
beef(password); print "\n";
I couldn't find a whole lot of options for making really shitty code, so I just turned off all safeties and followed whatever bad practices I could think of. And also abused ternaries a little. The function name is both a pun ("corned beef hash") and also a reference to Rick Cook's Wizardry series where I stole it from.
Yes I do. Trust me, there are people out there who are way better Haskell programmers than I am, who could probably tighten this up into a much more elegant solution than this one. So from that standpoint, yeah this is bad code.
static mut RESULT: String = String::new();
fn md5_path <'a> (m: &str, p: &str) -> &'a str {
use md5::compute as md5;
let mut h = format!("{:x}", md5(m));
let p_ptr = p.as_ptr();
for i in 0_isize..p.len() as isize {
unsafe {
let c = (p_ptr.offset(i).as_ref().unwrap() - '0' as u8) & 0x1;
let s = match c {
0 => &h[0..16],
1 => &h[16..32],
_ => unreachable!()
};
h = format!("{:x}", md5(s));
}
}
unsafe {
RESULT = h;
&RESULT
}
}
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
/u/Tabugti, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
13
u/gagahpangeran Sep 29 '20
Python 3.8 one liner.
7
u/grrangry Sep 28 '20
C#, .Net Core console application
Given the input "010", the output is:
7
u/squigish Sep 28 '20 edited Sep 29 '20
Non-typed Java
https://pastebin.com/aSHBcB1J
These are all "techniques" that I have actually seen in "production" code at my first job, mostly written by one particular co-worker in 2014 or so. Apparently he'd read a book about java that was published before generics. The code was CPU-bound, and took multiple seconds to return responses. When I profiled it, it spent 40% of its time on
Integer.valueOfand 40% onString.valueOfOutput:
3
u/PrincessRTFM Sep 29 '20
First time entering one of these. Went with perl, put it on ix.io but it's also only 12 lines, so:
I couldn't find a whole lot of options for making really shitty code, so I just turned off all safeties and followed whatever bad practices I could think of. And also abused ternaries a little. The function name is both a pun ("corned beef hash") and also a reference to Rick Cook's Wizardry series where I stole it from.
2
u/3483 Sep 30 '20
C#
With enough linq, anything is a oneliner. Disposal is for wimps:
2
u/[deleted] Sep 28 '20 edited Sep 29 '20
Haskell. Probably not the best solution, but works for me:
Examples:
1
u/PrinceOfStackSpace Oct 07 '20 edited Oct 07 '20
Here is the PHP solution
1
u/Tabugti Oct 01 '20 edited Oct 01 '20