this post was submitted on 29 Jun 2025
-3 points (33.3% liked)

C++

2040 readers
2 users here now

The center for all discussion and news regarding C++.

Rules

founded 2 years ago
MODERATORS
 

Hi! ✌️ I need to generate some string in C++ with random characters that can use all letters from "a" to "z" (include capital letters), and all numbers from 0 to 9 there.

And for examples this should looks somehow like this:

SnHXAsOC5XDYLgiKM5ly

Also I want to encrypt that string then by itself:

SnHXAsOC5XDYLgiKM5ly encrypt with SnHXAsOC5XDYLgiKM5ly key.

So, how can I do this in C++? 🤔

Thanks in advance!

you are viewing a single comment's thread
view the rest of the comments
[–] lambalicious@lemmy.sdf.org 1 points 5 days ago* (last edited 5 days ago) (3 children)

There are various ways to solve the first part and they're pretty generic, the only "C++-specific" part is whether you'll want to build the string step by step (adding characters) or build in one go then modify (build a prearranged string, for example of a specific size, then modify as needed).

To solve the second part we (you) also need to know the encryption algorithm. "Encrypt" is quite a generic word.

[–] xolatgames@programming.dev 2 points 5 days ago* (last edited 5 days ago) (1 children)

Let's solve the first part then.

But I guess that @herzenschein already suggested me a solution...

You could take inspiration from Theodore Tso’s pwgen: https://github.com/tytso/pwgen

[–] lambalicious@lemmy.sdf.org 1 points 4 days ago

Oh good I had forgotten that part!

load more comments (1 replies)