Skip to main content
  1. Posts/

apg.go - Yet another APG clone

·811 words·4 mins

You may remember my previous blog entry about my APG-clone written in Perl. Well, since I just started learning Go I used it as my first project.

A different programming langauge #

I mainly build stuff in the classic scripting languages like Perl, Java-/TypeScript, ZSH/Bash. And while I enjoy using those languages, I often find it fairly annoying having to install lots of packages, dependencies and stuff just to run a simple program. Therefore an alternative language, that can be complied and is capable of running on multiple platforms, is something I was eager to learn. Sure, I could use C or C++, but frankly my C/C++ is so rusty, that chances are high, that I add lots of memory leaks and fucked up pointers to my programs. So I’d rather use something that takes this burden of my shoulders - in other word: that is memory-safe.

I looked at different options:

  • C#/.NET: Given that we use C#/.NET at work and that I know my way around in C/C++, I have already some experience with it. I really like the langauge. It’s easy to write and very powerful. And since .NET-core you can even run it on Linux. But shipping the whole .NET(-core) libs just to print out “hello world” does not really fit my usual workflow. So, I decided not to use it as my “go-to” language for projects I want to compile
  • Rust: Rust is pretty “in” right now. It’s praised for it’s memory-safety and robustnes, but the learning curve is pretty steep. I really didn’t like the syntax too.
  • Swift: Swift is Apple’s alternative to Objective-C. It’s a mixutre of Objective-C, Rust, Haskell, Ruby, Python, and C#. After some playing around, I really enjoyed using that language. Unfortunately it currently only propperly works on MacOS. Yes, there is a Windows Toolchain, but the installation was painful and failed too often on my Windows box. Same applies to my Linux box. Therefore Swift - unfortunately - will not be my new “go-to” language
  • Go: Go is Google’s language of choice. It run/compiles on Linux/Windows/BSD/MacOS (and recently even zOS). After playing around with it for an evening, I immediately fell in love. It has a simple syntax, yet is a powerful and fast language. I like the idea of not being bound to OOP paradigm but rather using the concept of Interfaces. Also goroutines as platform for concurrency is pretty cool. I immediately felt at home and decided to dig deeper.

apg.go #

As I wanted to gain some more experience, I settled for a simple project, that shouldn’t be too hard to build with my very limited Go-knowledge. I decided to use my APG clone written in Perl apg.pl as my first real project.

First I tried to replicate the featureset of apg.pl. Once I got that working in Go, I started to implement more features of the original APG. I also took the opportunity to build some propper testing, to also familiarise myself with how tests work in Go.

The result can be found here: apg.go

Binary releases #

What’s very cool is, that github.com supports Go workflows out of the box. This way I can build, test and release directly from github.com. Once I am satisfied with the current state of the code, I simply create a new release-tag and Github will automagically build APG binaries for all platforms and architectures, it will zip the files (together with the LICENSE and README.md) and attach it to the release page. This is something I was never able to do with my usual Perl/TypeScript/Bash scripts.

Old and new features #

As said, I implemented the same functionality as apg.pl but also added some new features, like the spelling of passwords or using the -M parameter to specify password types in one go.

CLI options available #

  • -m <length>: The minimum length of the password to be generated (Default: 20)
  • -x <length>: The maximum length of the password to be generated (Default: 20)
  • -n <number of passwords>: The amount of passwords to be generated (Default: 1)
  • -E <list of characters>: Do not use the specified characters in generated passwords
  • -M <[LUNSHClunshc]>: New style password parameters (upper-case enables, lower-case disables)
  • ``-L`: Use lower-case characters in passwords (Default: on)
  • -U: Use upper-case characters in passwords (Default: on)
  • -N: Use numeric characters in passwords (Default: on)
  • -S: Use special characters in passwords (Default: off)
  • -H: Avoid ambiguous characters in passwords (i. e.: 1, l, I, o, O, 0) (Default: off)
  • -C: Generate complex passwords (implies -L -U -N -S and disables -H) (Default: off)
  • -l: Spell generated passwords (Default: off)
  • -h: Show a CLI help text
  • -v: Show the version number

apg.go is FOSS #

Same as apg.pl, I released apg.go as OSS under the MIT license. So feel free to use the software and enhance it to your liking. PR are welcome.