Skip to content

Commit

Permalink
Reorganize lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik99999 committed Feb 22, 2024
1 parent 29e8623 commit 34d8af9
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 21 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 4 additions & 8 deletions src/lib/rtdx/generate.ts → src/lib/generators/rtdx/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ function shuffle(code: string[]): string[] {
* Converts indexes to symbols
*/
function toSymbols(indexes: number[]): string[] {
const code: string[] = [];
for (const i of indexes) {
code.push(symbols[i]);
}
return code;
return indexes.map((i) => symbols[i]);
}

/**
* Unpacks the code
*/
function unpack(bitstream: number[]): number[] {
function bitunpack(bits: number[]): number[] {
const unpacked: number[] = [];
const reader = new BitstreamReader(bitstream, 8);
const reader = new BitstreamReader(bits, 8);
while (reader.remaining()) {
unpacked.push(reader.read(6));
}
Expand Down Expand Up @@ -109,7 +105,7 @@ function serialize(data: RescueData | RevivalData): string {
const indexes = writer.finish();
indexes.unshift(checksum(indexes));
const encrypted = encrypt(indexes);
const bitstream = unpack(encrypted);
const bitstream = bitunpack(encrypted);
const symbols = toSymbols(bitstream);
const code = shuffle(symbols);
return code.join('');
Expand Down
File renamed without changes.
12 changes: 2 additions & 10 deletions src/lib/rtdx/read.ts → src/lib/generators/rtdx/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Data } from './data';
* Splits code string into array
*/
function splitCode(code: string): string[] {
code = code.replace(' ', '').toLowerCase();
code = code.replace(/\s/g, '').toLowerCase();
let codeToSplit = '';
for (let i = 0; i < code.length; i += 2) {
codeToSplit += code.slice(i, i + 2) + ' ';
Expand All @@ -32,15 +32,7 @@ function unshuffle(code: string[]): string[] {
* Converts symbols to indexes 0-63
*/
function toIndexes(code: string[]): number[] {
const indexes: number[] = [];
for (let i = 0; i < code.length; i++) {
for (let j = 0; j < symbols.length; j++) {
if (symbols[j] === code[i]) {
indexes[i] = j;
}
}
}
return indexes;
return code.map((c) => symbols.indexOf(c));
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/routes/(rtdx)/PasswordImage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
const characters = password.toLowerCase().match(/.{1,2}/g)!;
for (let i = 0; i < 30; i++) {
const pos = i % 15;
const x = 71 + (pos * 54) + (Math.floor(pos / 5) * 8.5);
const x = 71 + pos * 54 + Math.floor(pos / 5) * 8.5;
const y = 71 + (i >= 15 ? 69 : 0) + (pos >= 5 && pos <= 9 ? 8.5 : 0);
drawCharacter(characters[i], x, y);
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(rtdx)/rtdx-rescue/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { base } from '$app/paths';
import { RTDX } from '$lib';
import { RTDX } from '$lib/generators';
import PasswordImage from '../PasswordImage.svelte';
let password: string;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(rtdx)/rtdx-revival/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { base } from '$app/paths';
import { RTDX } from '$lib';
import { RTDX } from '$lib/generators';
import PasswordImage from '../PasswordImage.svelte';
let password: string;
Expand Down

0 comments on commit 34d8af9

Please sign in to comment.