Hide text in MP3

In the world, all people are divided into two types: some want to hide something , while others , on the contrary, want to find something . Today we will be on the side of the first. We will hide.
Many people probably already know how to hide files in the system. But few people know how to hide text in files, but so that it would not be visible. And so let's get started.
We will hide the plain text from the "txt" file. And we will record it in mp3 files. Many people know that there are tags in mp3 files. But hardly anyone wondered what their length is and what can be done with them. Wikipedia says tag length
  • title
  • executor
  • album

equals 30 characters. There is still a Comment tag , but we will not touch it.
Tags can be changed using special programs. Such as for example Mp3Tag .
What and where we will write figured out. Now decide on what we will write. For these purposes, I chose PHP and PEAR package MP3_Id . To this set we need to add a virtual server, Denwer or XAMPP or some other. Whoever you like.
Our tool will consist of two scripts, one of which will record, and the other will read MP3 tags accordingly.

First you need to install the PEAR MP3_Id module:

  1. Start Menu-> Run-> CMD
  2. Go to the directory where the php interpreter is installed -> pear install MP3_Id

Let's start the analysis of scripts.

Script number one. read.php


Below, the functions used in this script will be listed and parsed.

We need a function that counts the number of lines of 30 characters in a file.

function CalcSize($f) //рассчитываем количество строк по 30 символов
{
	$size = 0; //количествое символов в файле
	while(!feof($f))
	{
		fread($f, 1);
		$size++;
	}
	$dataCount = floor($size / 30) + 1;
//на 30 без остатка не получится разделить поэтому на всякий случай прибавляем еще одну сточку.
	fclose($f);
	return $dataCount; 
// возвращаем количество строк по 30 символов
}


A function that reads 30 characters from a file into an array.

function ReadDataFiles($size) 
{
	$arr = array();
	$f = fopen('data.txt','rb');
	for($i = 0; $i < $size; $i++)
	{
		$arr[$i] = fread($f, 30);//пишем в строчку по 30 смволов
	}
	fclose($f);
	return $arr;
}


Functions for working with tags.
Reading:
function ReadTags($file) 
{
	echo $file.' ';
	$mp3 = &new MP3_Id();
	$result = $mp3->read($file);
	echo $mp3->getTag('name');
	echo $mp3->getTag('artists');
	echo $mp3->getTag('album');
}


Record:
function SetTags($file, $data1,$data2,$data3) 
{
	$mp3 = &new MP3_Id();
	$result = $mp3->read($file);
	$mp3->setTag('name', $data1);
	$mp3->setTag('artists', $data2);
	$mp3->setTag('album', $data3);
	$result = $mp3->write();
}


We also need to create arbitrary file names. We will just take one source and copy it.

function GenerateName()
{
	$abc = array('q','w','e','r','t','y',
         			 'u','i','o','p','a','s',
				 'd','f','g','h','j','k',
				 'l','z','x','c','v','b',
				 'n','m','1','2','3','4',
				 '5','6','7','8','9','0');
	$name="";
	for($i = 0; $i < 8; $i++)
	{
		$index = rand(0, count($abc) - 1);
		$name .= $abc[$index];
	}
	return $name;
}


And so we have all the necessary functions. You can compose a script structure.
We will connect the newly installed module.
require_once 'MP3/Id.php';


$fileSize = CalcSize(); // количество строк по 30 символов
$words = ReadDataFiles($fileSize);// массив со строками


And here is a function that hides text in tags. Her input is served: an array with strings, and the number of rows.

function HideData($arr, $number)
{
        $numberMp3Files = floor($number / 3) + 1;
//количество мп3 файлов для заливки(делаем на один больше потому что округление происходит в меньшую //сторону
	mkdir('files');//создаем дерикторию для файлов
        for($i = 0; $i < $numberMp3Files; $i++) // создаем файлы
	{
		$name = GenerateName();	
		$name .= '.mp3';
		copy('file.mp3','files/'.$name);// копируем 
	} 
        chdir('files');// переходим в нее
	$list = glob('*.mp3'); // получаем список mp3 файлов
	sort($list);	//сортируем по увеличению
	$a = 0; // счетчик для слов
	$b = 0; // стечик для записаных файлов
	for($i = 0; $i < count($list); $i++)
	{
		SetTags($list[$i],$arr[$a],$arr[$a+1],$arr[$a+2]);
		$a +=3; 
		if($b < count($list))$b++; //если количество записаных файлов меньше то продолжаем
		else break; // иначе брейк
	}
}	


That's the whole script for writing text to mp3 file tags. I want to add that it is advisable to take a small MP3 file for copying. And call it file.mp3.

It remains to write a script that will return us all back. From mp3 tags to a text file.

Script number two. write.php



Connect the PEAR module again
require_once 'MP3/Id.php';


Create a file for recording.
$handle = fopen("new_data.txt","w");


An already familiar function for reading tags. Slightly modified.
function ReadTags($file, $fo)
{
	$mp3 = &new MP3_Id();
	$result = $mp3->read($file);
	$name = $mp3->getTag('name');
	$srtists = $mp3->getTag('artists');
	$album = $mp3->getTag('album');
	fputs($fo, "$name");
	fputs($fo,"$artists");
	fputs($fo, "$album");
	}


Go to the directory with the files.
chdir('files');


create a list of MP3 files
$list = glob('*.mp3');


Sort it
sort($list);


And for each file we call the ReadTags function
foreach($list as $a)
{
	ReadTags($a, $handle);
}


How to work with PEAR MP3_Id is better to look at offsite. I will hardly explain clearly. During the experiments, it was revealed that if the source file has some tags, then in windows the created files have the same tags. But at the same time, our information is recorded in them and read perfectly. And if there are no tags, then ours are written, which are perfectly visible in the explorer. So it’s better to use a tagged file, and then everything will definitely be super secret.
If you find any errors, or know how to improve the script, be sure to write. I will only be glad. I apologize for errors in the design of the post, he is the first.

Also popular now: