Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to base64 encode /dev/random or /dev/urandom?

cat /dev/urandom is always a fun way to create scrolling characters on your display, but produces too many non-printable characters.

Is there an easy way to encode it on the command-line in such a way that all of its output are readable characters, base64 or uuencode for example.

Note that I prefer solutions that require no additional files to be created.

like image 741
alexanderpas Avatar asked Aug 08 '09 23:08

alexanderpas


People also ask

What does Base64 Dev Urandom do?

cat /dev/urandom is always a fun way to create scrolling characters on your display, but produces too many non-printable characters. Is there an easy way to encode it on the command-line in such a way that all of its output are readable characters, base64 or uuencode for example.

What is cat Dev Urandom?

/dev/urandom is a continuous stream of random data. It will never produce an end of file. Buffered reads will fill the read buffer, so even if you are piping the output of cat into some other program, the read won't be terminated until the pipe is closed.


1 Answers

What about something like

cat /dev/urandom | base64 

Which gives (lots of) stuff like

hX6VYoTG6n+suzKhPl35rI+Bsef8FwVKDYlzEJ2i5HLKa38SLLrE9bW9jViSR1PJGsDmNOEgWu+6 HdYm9SsRDcvDlZAdMXAiHBmq6BZXnj0w87YbdMnB0e2fyUY6ZkiHw+A0oNWCnJLME9/6vJUGsnPL TEw4YI0fX5ZUvItt0skSSmI5EhaZn09gWEBKRjXVoGCOWVlXbOURkOcbemhsF1pGsRE2WKiOSvsr Xj/5swkAA5csea1TW5mQ1qe7GBls6QBYapkxEMmJxXvatxFWjHVT3lKV0YVR3SI2CxOBePUgWxiL ZkQccl+PGBWmkD7vW62bu1Lkp8edf7R/E653pi+e4WjLkN2wKl1uBbRroFsT71NzNBalvR/ZkFaa 2I04koI49ijYuqNojN5PoutNAVijyJDA9xMn1Z5UTdUB7LNerWiU64fUl+cgCC1g+nU2IOH7MEbv gT0Mr5V+XAeLJUJSkFmxqg75U+mnUkpFF2dJiWivjvnuFO+khdjbVYNMD11n4fCQvN9AywzH23uo 03iOY1uv27ENeBfieFxiRwFfEkPDgTyIL3W6zgL0MEvxetk5kc0EJTlhvin7PwD/BtosN2dlfPvw cjTKbdf43fru+WnFknH4cQq1LzN/foZqp+4FmoLjCvda21+Ckediz5mOhl0Gzuof8AuDFvReF5OU 

Or, without the (useless) cat+pipe :

base64 /dev/urandom 

(Same kind of output ^^ )


EDIT : you can also user the --wrap option of base64, to avoid having "short lines" :

base64 --wrap=0 /dev/urandom 

This will remove wrapping, and you'll get "full-screen" display ^^

like image 90
Pascal MARTIN Avatar answered Sep 22 '22 07:09

Pascal MARTIN