Added oracle guid converter (#7)

* Added oracle guid converter

* Simplify code

---------

Co-authored-by: Myx <info@azaaxin.com>
This commit is contained in:
Rasmus
2025-01-25 00:10:49 +01:00
committed by GitHub
parent a6a0399f1a
commit 9bb2d3ec23
5 changed files with 160 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import { ImageConverterComponent } from '../tools/server-side/image-converter/im
import { WordCounterComponent } from '../tools/client-side/word-counter/word-counter.component';
import { ColorPickerComponent } from '../tools/client-side/color-picker/color-picker.component';
import { QrCodeGeneratorComponent } from '../tools/client-side/qr-code-generator/qr-code-generator.component';
import { OracleGuidConverterComponent } from '../tools/client-side/oracle-guid-converter/oracle-guid-converter.component';
export const routes: Routes = [
{
@@ -60,6 +61,11 @@ export const routes: Routes = [
path: 'color-picker',
pathMatch: 'full',
component: ColorPickerComponent
},
{
path: 'oracle-guid-converter',
pathMatch: 'full',
component: OracleGuidConverterComponent
}
];

View File

@@ -88,6 +88,11 @@ export class HeaderComponent implements OnInit {
label: 'Ascii to text',
routerLink: 'ascii-to-text',
routerLinkActiveOptions: { exact: true }
},
{
label: 'Oracle GUID Converter',
routerLink: 'oracle-guid-converter',
routerLinkActiveOptions: { exact: true }
}
]
}

View File

@@ -0,0 +1,9 @@
<app-dual-textarea
title="GUID to Oracle RAW(16) Converter"
topPlaceholder="Enter GUID here..."
bottomPlaceholder="Enter RAW(16) will appear here..."
[topValue]="convertedGuid"
[bottomValue]="rawOutput"
(topChange)="onConvertToRaw($event)"
(bottomChange)="onConvertToGuid($event)">
</app-dual-textarea>

View File

@@ -0,0 +1,40 @@
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
h2, h3, label {
color: #a5a5a5;
}
.conversion-section {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 100%;
}
}
:host ::ng-deep p { // Idk about this -.-
color: #a5a5a5;
}
input {
width: 100%;
padding: 10px;
font-size: 16px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}

View File

@@ -0,0 +1,100 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { DualTextareaComponent } from '../../../app/shared/dual-textarea/dual-textarea.component';
@Component({
selector: 'app-oracle-guid-converter',
standalone: true,
imports: [
FormsModule,
CommonModule,
DualTextareaComponent
],
templateUrl: './oracle-guid-converter.component.html',
styleUrl: './oracle-guid-converter.component.scss'
})
export class OracleGuidConverterComponent {
guidInput: string = '';
rawOutput: string = '';
convertedGuid: string = '';
onConvertToRaw(input: string): void {
if (this.isValidGuid(input)) {
this.rawOutput = this.guidToRaw(input);
} else {
this.rawOutput = 'Invalid GUID format';
}
}
onConvertToGuid(input: string): void {
if (this.isValidRaw(input)) {
this.convertedGuid = this.rawToGuid(input);
} else {
this.convertedGuid = 'Invalid RAW(16) format';
}
}
private isValidGuid(guid: string): boolean {
const guidPattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
return guidPattern.test(guid);
}
private isValidRaw(raw: string): boolean {
const rawPattern = /^[0-9a-fA-F]{32}$/;
return rawPattern.test(raw);
}
private guidToRaw(guid: string): string {
const hexParts = guid.replace(/-/g, '');
const guidBytes = Array.from({ length: 16 }, (_, i) =>
parseInt(hexParts.substr(i * 2, 2), 16)
);
const reorderedBytes = [
guidBytes[3],
guidBytes[2],
guidBytes[1],
guidBytes[0],
guidBytes[5],
guidBytes[4],
guidBytes[7],
guidBytes[6],
...guidBytes.slice(8, 16)
];
return reorderedBytes
.map(byte => byte.toString(16)
.padStart(2, '0'))
.join('')
.toUpperCase();
}
private rawToGuid(raw: string): string {
const rawBytes = Array.from({ length: 16 }, (_, i) =>
parseInt(raw.substring(i * 2, i * 2 + 2), 16)
);
const reorderedBytes = [
rawBytes[3],
rawBytes[2],
rawBytes[1],
rawBytes[0],
rawBytes[5],
rawBytes[4],
rawBytes[7],
rawBytes[6],
...rawBytes.slice(8, 16)
];
const hexArray = reorderedBytes.map(b => b.toString(16).padStart(2, '0'));
return [
hexArray.slice(0, 4).join(''),
hexArray.slice(4, 6).join(''),
hexArray.slice(6, 8).join(''),
hexArray.slice(8, 10).join(''),
hexArray.slice(10, 16).join('')
].join('-');
}
}