This repository has been archived by the owner on Jun 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aopacket.cpp
98 lines (75 loc) · 2.01 KB
/
aopacket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//////////////////////////////////////////////////
//
// This work is licensed under the MIT license.
//
// You are free to copy, modify and distribute
// this work freely given that proper attribution
// is supplied and the author is not held liable.
// See LICENSE for details.
//
// Copyright (c) 2016-2018 David "OmniTroid" Skoland
//
//////////////////////////////////////////////////
#include "aopacket.h"
#include "encryption_functions.h"
#include <QDebug>
AOPacket::AOPacket(QString p_packet_string)
{
QStringList packet_contents = p_packet_string.split("#");
m_header = packet_contents.at(0);
for(int n_string = 1 ; n_string < packet_contents.size() - 1 ; ++n_string)
{
m_contents.append(packet_contents.at(n_string));
}
}
AOPacket::AOPacket(QString p_header, QStringList &p_contents)
{
m_header = p_header;
m_contents = p_contents;
}
AOPacket::~AOPacket()
{
}
QString AOPacket::to_string()
{
QString f_string = m_header;
for (QString i_string : m_contents)
{
f_string += ("#" + i_string);
}
f_string += "#%";
if (encrypted)
return "#" + f_string;
else
return f_string;
}
void AOPacket::encrypt_header(unsigned int p_key)
{
m_header = fanta_encrypt(m_header, p_key);
encrypted = true;
}
void AOPacket::decrypt_header(unsigned int p_key)
{
m_header = fanta_decrypt(m_header, p_key);
encrypted = false;
}
void AOPacket::net_encode()
{
for (int n_element = 0 ; n_element < m_contents.size() ; ++n_element)
{
QString f_element = m_contents.at(n_element);
f_element.replace("#", "<num>").replace("%", "<percent>").replace("$", "<dollar>").replace("&", "<and>");
m_contents.removeAt(n_element);
m_contents.insert(n_element, f_element);
}
}
void AOPacket::net_decode()
{
for (int n_element = 0 ; n_element < m_contents.size() ; ++n_element)
{
QString f_element = m_contents.at(n_element);
f_element.replace("<num>", "#").replace("<percent>", "%").replace("<dollar>", "$").replace("<and>", "&");
m_contents.removeAt(n_element);
m_contents.insert(n_element, f_element);
}
}