Skip to content

Instantly share code, notes, and snippets.

@Fank
Last active August 29, 2024 17:52
Show Gist options
  • Save Fank/11127158 to your computer and use it in GitHub Desktop.
Save Fank/11127158 to your computer and use it in GitHub Desktop.
ArmA 3 / DayZ-Standalone - BattlEye GUID calculation

md5("BE" (2 bytes) + 64-bit SteamID (8 bytes))

std::stringstream bestring;
__int64 steamID = 76561197996545192;
__int8 i = 0, parts[8] = { 0 };
do parts[i++] = steamID & 0xFF;
while (steamID >>= 8);
bestring << "BE";
for (int i = 0; i < sizeof(parts); i++) {
bestring << char(parts[i]);
}
// I used this md5 library http://www.zedwood.com/article/cpp-md5-function
std::cout << md5(bestring.str()) << std::endl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Int64 SteamId = 76561197996545192;
byte[] parts = { 0x42, 0x45, 0, 0, 0, 0, 0, 0, 0, 0 };
byte counter = 2;
do
{
parts[counter++] = (byte)(SteamId & 0xFF);
} while ((SteamId >>= 8) > 0);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] beHash = md5.ComputeHash(parts);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < beHash.Length; i++)
{
sb.Append(beHash[i].ToString("x2"));
}
Console.Out.WriteLine(sb.ToString());
Console.In.Read();
}
}
}
// Thanks to nano2k
package main
import (
"crypto/md5"
"fmt"
)
func main() {
steamid := 76561197996545192
h := md5.New()
h.Write([]byte("BE"))
for i := 0; i < 8; i++ {
h.Write([]byte{byte(steamid & 0xFF)})
steamid >>= 8
}
fmt.Printf("Battleye GUID: %x", h.Sum(nil))
}
var crypto = require('crypto');
var int64 = require('int64-native');
var md5Hash = crypto.createHash('md5');
var steamId = new int64('76561197996545192'); // The steamid must be a STRING! not a number!
md5Hash.update('BE');
for (var i = 0; i < 8; i++) {
md5Hash.update(String.fromCharCode(steamId.and(0xFF).toNumber()));
steamId = steamId.shiftRight(8);
}
console.log(md5Hash.digest('hex'));
<?php //Cheers Rommel
/* Verify that following value is higher than 2147483647(32bit):
echo PHP_INT_MAX;
*/
$steamID = '76561197996545192';
$temp = '';
for ($i = 0; $i < 8; $i++) {
$temp .= chr($steamID & 0xFF);
$steamID >>= 8;
}
$return = md5('BE' . $temp);
echo $return;
?>
# Thanks to gunlinux
import md5
steamid=76561197996545192
temp = ""
for i in range(8):
temp += chr((steamid & 0xFF))
steamid >>= 8
m = md5.new("BE"+temp)
print m.hexdigest()
-- Microsoft SQL Server
-- https://github.com/Fankserver/Microsoft-SQL-Server-Assemblies/tree/master/BattlEye
SELECT SteamIdToBattlEyeGUID(76561197996545192);
@NPG-Soul
Copy link

Fank, can this be done the other way around to? Like from guid to SteamId?

@nuxil
Copy link

nuxil commented Jan 28, 2015

NPG-Soul
No, thats not possible. you cant reverse a MD5sum..
There is also bitwise (shifting, and) operations involved here aswell

Note to the python example
In python 2.6.6 you will get a import error on md5. Instead use hashlib
from hashlib import md5

@BlackCetha
Copy link

Is there a way to make it work with php 32bit? Like a library or something?
I can't seem to find a 64 bit version of PHP.

@CameronHall
Copy link

No BlackCetha, the Steam ID is a 64 bit integer, hence a 64 bit version of PHP is required. Depending on your Linux flavour it should be as simple 'sudo apt-get install php' to install the 64 bit version, provided your OS is 64 bit. For windows you can get it from here http://windows.php.net/download/.

@Fank
Copy link
Author

Fank commented Mar 6, 2015

@NPG-Soul I started a project a long time ago, which will render all possible BattlEyeGUID's for all SteamIds so you can Search a BattlEyeGUID and will get the SteamId for it. But i stopped it.

@nuxil can you please fork the gist and publish a possible fix for this? So i can update it.

@BlackCetha There is no way to convert a SteamId in a language which won't support 32bit.

@D3RFLO
Copy link

D3RFLO commented May 21, 2016

Can i convert the GUID to Steam ID?

@klemmchr
Copy link

@frank I forked this Gist and added a MySQL function for calculating the GUID: https://gist.github.com/chris579/53053b6d6438df9a9718c23c0d6bbd69

@BarackHussein0bama
Copy link

@NPG-Soul @Fank @D3RFLO Convert GUID to SteamID64 https://guid2steamid.pw

@Lynxaa
Copy link

Lynxaa commented Oct 6, 2017

php

function beguid($id) {
	$result = '';
	for ($i = 0; $i < 8; $i++) {		
		$result .= chr(gmp_strval(gmp_and($id, 0xFF)));
		$id = gmp_div($id, gmp_pow(2, 8));
	}
	return md5('BE' . $result);
}

$guid = beguid(gmp_abs(steamid));

@AWildTeddyBear
Copy link

AWildTeddyBear commented Mar 29, 2018

Much easier version of the C++ one: (I'm sure it can be simplified even more, not sure. ;P)

std::string computeSteam64BattlEyeGUID(long long steam64ID){
    std::string bestring = "BE";
    for(size_t i = 0; i == 0 || (steam64ID >>= 8); bestring += (steam64ID & 0xFF), ++i);
    return md5(bestring); //http://www.zedwood.com/article/cpp-md5-function
}

@cat24max
Copy link

Modern approach to reverse-lookup: https://github.com/Multivit4min/beguid-converter/

@maca134
Copy link

maca134 commented Nov 30, 2019

Here is a nodejs implementation that needs no external deps as long as your running +10.4.0

// nodejs +10.4.0
import { createHash } from 'crypto';

const steamId = 76561197996545192n; // cd97cc68c1038b485b081ba2aa3ea6fa
const bytes = [];

for (let i = 0; i < 8; i++) {
	bytes.push(Number((steamId >> (8n * BigInt(i))) & 0xffn));
}

const guid = createHash('md5').update(Buffer.from([0x42, 0x45, ...bytes])).digest('hex');

console.log(guid);

@0FakE
Copy link

0FakE commented Sep 3, 2020

Fank, can this be done the other way around to? Like from guid to SteamId?

Yes you can.

Use the free reverse-lookup / converter: https://devt0ols.net/converter

Available on each browser and any mobile device.

Valid lookup values: Steam (Vanity) URL, Steam ID, Steam ID 3, Steam ID 64, BattlEye ID, Bohemia ID


REST API

https://devt0ols.net/converter/?inc=help/api

Example response:

{
  "error": false,
  "result": {
    "steam_url": "https://steamcommunity.com/profiles/76561197960265729",
    "steam_id": "STEAM_0:1:0",
    "steam_id3": "[U:1:1]",
    "steam_id64": "76561197960265729",
    "battleye_id": "74ae012b5407e0a3cc2cd82ec1f8ba7d",
    "bohemia_id": "ccuWIpEIrX_wmD5VsthErf1qNQbEK7IdG6fL1Il4KuA=",
    "requests": 1
  }
}

Discord BOT

https://devt0ols.net/converter/?inc=main/bot

Invitation link: ID Bot

The BOT is able to lookup and convert each of the mentioned values above.

@cat24max
Copy link

cat24max commented Sep 3, 2020

There is also the AllianceApps API: https://allianceapps.io/beguid

Or if you would like to host it yourself: https://github.com/Multivit4min/beguid-converter

Edit: Just realized I shared this link already :D

But no, you cannot convert it directly (without a rainbow table).

@ignaciochemes
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment