Created
February 26, 2014 17:40
-
-
Save fabiomontefuscolo/9234485 to your computer and use it in GitHub Desktop.
remove obsfucação dos arquivos do dicionário houaiss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
# -*- coding: utf-8 -*- | |
# | |
# Coloque esse script na pasta com os arquivos dhx. | |
# O resultado estará em iso-8859-1 | |
# | |
# | |
# Segui o tutorial em http://www.caloni.com.br/blog/archives/conversor-de-houaiss-para-babylon-parte-1 | |
# | |
import os | |
files = os.listdir('.') | |
for arq in files: | |
if not arq.endswith('dhx'): | |
continue | |
print 'Abrindo "%s"' % arq | |
origin = open(arq, 'r') | |
target = open('%s.txt' % arq, 'w+') | |
char = origin.read(1) | |
while char: | |
byte = ord(char) + 0x0B | |
new_char = chr(byte % 256) | |
target.write(new_char) | |
char = origin.read(1) | |
origin.close() | |
target.close() |
apompeia
commented
Apr 6, 2021
via email
Obrigado, essa parte fiz convertendo py em VB
Como você fez para incluir no novo dicionario?
Sucesso
Alvaro
…________________________________
De: Carlos Francisco Pinheiro ***@***.***>
Enviado: segunda-feira, 5 de abril de 2021 20:04
Para: fabiomontefuscolo ***@***.***>
Cc: apompeia ***@***.***>; Comment ***@***.***>
Assunto: Re: fabiomontefuscolo/desobsfuscahouaiss.py
@chicolismo commented on this gist.
________________________________
A quem interessar possa, testei com clang:
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
/*
* Colocar o executável na mesma pasta dos arquivos .dhx
*/
void convert(const char *entry_name) {
fprintf(stdout, "Convertendo o arquivo '%s'\n", entry_name);
FILE *input;
if ((input = fopen(entry_name, "rb")) == NULL) {
fprintf(stderr, "Erro ao ler o arquivo '%s'\n", entry_name);
return;
}
// O novo nome que ter 5 caracteres a mais para incluir ".txt\0" no final
const size_t len = strlen(entry_name) + 5;
char *output_name = malloc(sizeof(char) * len);
snprintf(output_name, len, "%s.txt", entry_name);
FILE *output;
if ((output = fopen(output_name, "wb")) == NULL) {
fprintf(stderr, "Erro ao criar o arquivo '%s'\n", output_name);
fclose(input);
free(output_name);
return;
}
unsigned char byte = fgetc(input);
while (!feof(input)) {
fputc(byte + 0x0B, output);
byte = fgetc(input);
}
fclose(input);
fclose(output);
free(output_name);
}
const char *extension(const char *entry_name) {
const char *dot = strrchr(entry_name, '.');
if (!dot || dot == entry_name) {
return "";
}
return dot + 1;
}
int main() {
DIR *dir = opendir(".");
if (!dir) {
fprintf(stderr, "Erro ao abrir o diretório atual\n");
}
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
if (strcasecmp(extension(entry->d_name), "dhx") == 0) {
convert(entry->d_name);
}
}
closedir(dir);
return EXIT_SUCCESS;
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<https://gist.github.com/9234485#gistcomment-3694211>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AIZJN6Q6L3TLL66SA7RTIJDTHI6W7ANCNFSM4U6CCIUQ>.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment