Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 04 12:26
    @dom96 banned @acroobat
  • Mar 03 2017 15:52
    @dom96 banned @Octopoda7
  • Feb 12 2017 23:57
    @dom96 banned @zzz125
  • Dec 23 2016 19:43
    @dom96 banned @Izrab
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
well, not really
strenc is really fragile, it's just a poc
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
sure it is, in fact I'd like to use it for just a couple if strings, not the whole project
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
I'm not sure why it got so much attention, because it really doesn't work well, and I don't know how to make it work well :)
I think you'd want to write some other code then, you don't need term rewriting for that
You can just have a template or macro that encrypts the string at compile time and decrypts at runtime, and call it explicitly
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
yes, I started from strenc because I liked the simple idea of rolling enc linked to built time. I should probably go nimcrypt, but I'm now experienced in encryption in general
Rika#2434
@_discord_259277943275126785:t2bot.io
[m]
strenc isnt really encryption though
the key is still on the binary
its as encryption as base64 is
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
yes yes I know, I just want to hide from kids
and also play around this, just because of nim
I yet have to find a proper use of compile time magic
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
well technically it is encryption if you didn't know the xor key :) but it can be easily bruteforced, yes
Rika#2434
@_discord_259277943275126785:t2bot.io
[m]
yeah but it's still on the binary innit?
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
yes, in strenc case, but xor encryption itself is different from base-n
Rika#2434
@_discord_259277943275126785:t2bot.io
[m]
yes in that case
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
base-n is just an encoding
Rika#2434
@_discord_259277943275126785:t2bot.io
[m]
i mean only in strencs case
anywhere else yes its encryption
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
Well, as I said you can easily create your own strenc with encryption for specific strings
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
sure I'm going that direction, also pulling in nimcrypto as I've never used it before and seems solid
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
any reason why?
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
no, just out of personal interest
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
yeah, i know that term-rewriting macros have a lot of issues
they might be even removed in the future
liuxiaodong
@gogolxdong
what's the way of doing static linking?
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
I'm unwrapping strenc into manual mode
--passL:"-static" in your project.nims
there are multiple ways actually
liuxiaodong
@gogolxdong
like link against libmariadb.dll?
tried , but didn't link together
Zoom
@Zoom:matrix.org
[m]
Hey guys, any patterns you use for --dry-run or other options which are frequently-checked but permanent for all the running time of your program?
I move the whole main loop into an fooImpl template with a bool parameter and instantiate a proc based on the user settings. Is there a reason I should not do it? I understand the implications of having multiple such options in a template, of course :D
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
not sure I understood your question, but can't you just parse user configuration into some object initially, and then just pass that object around?
it'll be pretty efficient and easy to use
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
Yardanico: I've converted the term rewriting macro into a simple macro and I'm encrypting the result of a staticRead. I'm compiling with --d:release and --passL:-s, but "stings mylib.so | grep contents" results in perfectly readable stuff
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
how exactly are you doing it?
first of all, if you have a const string nim will decrypt it at compile time anyway
and then the C compiler might also try to do a similar thing
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
well, that's what's happening probably. The only changed line from your code is the signature: macro encrypt*(s: static[string]): untyped =
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
this works just fine for me:
import std/[macros, hashes]

# Use a "strange" name
proc gkkaekgaEE(s: string, key: int): string {.noinline.} =
  # We need {.noinline.} here because otherwise C compiler
  # aggresively inlines this procedure for EACH string which results
  # in more assembly instructions
  var k = key
  result = s
  for i in 0 ..< result.len:
    for f in [0, 8, 16, 24]:
      result[i] = chr(uint8(result[i]) xor uint8((k shr f) and 0xFF))
    k = k +% 1

var encodedCounter {.compileTime.} = hash(CompileTime & CompileDate) and 0x7FFFFFFF

macro enc*(s: string): untyped =
  var encodedStr = gkkaekgaEE($s, encodedCounter)

  result = quote do:
    gkkaekgaEE(`encodedStr`, `encodedCounter`)

  encodedCounter = (encodedCounter *% 16777619) and 0x7FFFFFFF


let testStr = enc("hello world!")
echo testStr
obviously your string has to be var or let, otherwise it'll be decrypted at compile-time
and yeah, you can change the macro arg to static[string], that won't hurt
arkanoid[IRC]#0000
@_discord_709044657232936960_arkanoid=5b=49=52=43=5d:t2bot.io
[m]
found my error while you were typing. I has the equivalent of "const testStr = enc("hello world!")", so compiler was running symmetric crypt function twice at compile time
Yardanico#5346
@_discord_177365113899057152:t2bot.io
[m]
this is when compiling with arc - the C code simply references the encoded string and the xor decryption key to it, and assings the result to the variable
which is then assigned to testStr and fed to echo, then destroyed