Skip to content

Commit

Permalink
Fixed a bug in the token calculation for Google and Baidu
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinflower committed Jul 23, 2018
1 parent d865811 commit c83b80d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
24 changes: 14 additions & 10 deletions exe/TranslationWindows/HttpWindows/BaiduWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ std::string e(const char *pStr)
int64_t A = (int32_t)r.at(v);
if(128 > A)
S.push_back(A);
else if(2048 > A)
S.push_back(A >> 6 | 192);
else if(55296 == (64512 & A) && v + 1 < r.length() && 56320 == (64512 & r.at(v + 1)))
{
A = 65536 + ((1023 & A) << 10) + (1023 & r.at(++v));
S.push_back(A >> 18 | 240);
S.push_back(A >> 12 & 63 | 128);
}
else
{
S.push_back(A >> 12 | 224);
S.push_back(A >> 6 & 63 | 128);
if(2048 > A)
S.push_back(A >> 6 | 192);
else if(55296 == (64512 & A) && v + 1 < r.length() && 56320 == (64512 & r.at(v + 1)))
{
A = 65536 + ((1023 & A) << 10) + (1023 & r.at(++v));
S.push_back(A >> 18 | 240);
S.push_back(A >> 12 & 63 | 128);
}
else
{
S.push_back(A >> 12 | 224);
S.push_back(A >> 6 & 63 | 128);
}

S.push_back(63 & A | 128);
}
}
Expand Down
24 changes: 14 additions & 10 deletions exe/TranslationWindows/HttpWindows/GoogleWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ std::string tk(const wchar_t *pStr)
int64_t A = (int32_t)r.at(v);
if(128 > A)
S.push_back(A);
else if(2048 > A)
S.push_back(A >> 6 | 192);
else if(55296 == (64512 & A) && v + 1 < r.length() && 56320 == (64512 & r.at(v + 1)))
{
A = 65536 + ((1023 & A) << 10) + (1023 & r.at(++v));
S.push_back(A >> 18 | 240);
S.push_back(A >> 12 & 63 | 128);
}
else
{
S.push_back(A >> 12 | 224);
S.push_back(A >> 6 & 63 | 128);
if(2048 > A)
S.push_back(A >> 6 | 192);
else if(55296 == (64512 & A) && v + 1 < r.length() && 56320 == (64512 & r.at(v + 1)))
{
A = 65536 + ((1023 & A) << 10) + (1023 & r.at(++v));
S.push_back(A >> 18 | 240);
S.push_back(A >> 12 & 63 | 128);
}
else
{
S.push_back(A >> 12 | 224);
S.push_back(A >> 6 & 63 | 128);
}

S.push_back(63 & A | 128);
}
}
Expand Down

0 comments on commit c83b80d

Please sign in to comment.