Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Auto add RCPC Token & Add CPP 20 & Fix new codeforces sample #151

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
docopt "github.com/docopt/docopt-go"
)

const version = "v1.0.0"
const version = "v1.0.1"
const configPath = "~/.cf/config"
const sessionPath = "~/.cf/session"

Expand Down Expand Up @@ -63,7 +63,7 @@ Examples:
cf submit cf will detect what you want to submit automatically.
cf submit -f a.cpp
cf submit https://codeforces.com/contest/100/A
cf submit -f a.cpp 100A
cf submit -f a.cpp 100A
cf submit -f a.cpp 100 a
cf submit contest 100 a
cf submit gym 100001 a
Expand Down
2 changes: 2 additions & 0 deletions client/langs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Langs = map[string]string{
"42": "GNU G++11 5.1.0",
"50": "GNU G++14 6.4.0",
"54": "GNU G++17 7.3.0",
"73": "GNU G++20 11.2.0 (64 bit, winlibs)",
"2": "Microsoft Visual C++ 2010",
"59": "Microsoft Visual C++ 2017",
"9": "C# Mono 5.18",
Expand Down Expand Up @@ -60,6 +61,7 @@ var LangsExt = map[string]string{
"GNU C++11": "cpp",
"GNU C++14": "cpp",
"GNU C++17": "cpp",
"GNU G++20": "cpp",
"MS C++": "cpp",
"MS C++ 2017": "cpp",
"Mono C#": "cs",
Expand Down
42 changes: 41 additions & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"bufio"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -11,7 +12,10 @@ import (
"net/url"
"os"
"strconv"
"regexp"
"strings"
"crypto/aes"
"crypto/cipher"

"github.com/fatih/color"
)
Expand Down Expand Up @@ -72,14 +76,50 @@ func YesOrNo(note string) bool {
}
}

// GetBody read body
func SetRCPC(client *http.Client, body []byte, URL string) ([]byte, error) {
reg := regexp.MustCompile(`toNumbers\("(.+?)"\)`)
res := reg.FindAllStringSubmatch(string(body), -1)
text, _ := hex.DecodeString( res[2][1] )
key, _ := hex.DecodeString( res[0][1] )
iv, _ := hex.DecodeString( res[1][1] )

block, _ := aes.NewCipher(key)
mode := cipher.NewCBCDecrypter(block, iv)

mode.CryptBlocks([]byte(text), []byte(text))

var cookies []*http.Cookie
cookie := &http.Cookie{
Name: "RCPC",
Value: hex.EncodeToString(text),
Path: "/",
Domain: ".codeforces.com",
}
cookies = append(cookies, cookie)
u, _ := url.Parse("https://codeforces.com/")
client.Jar.SetCookies(u, cookies)

reg = regexp.MustCompile(`href="(.+?)"`)
link := reg.FindSubmatch(body)[1]
return GetBody( client, string(link) )
}

// GetBody read body
func GetBody(client *http.Client, URL string) ([]byte, error) {
resp, err := client.Get(URL)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body);
reg := regexp.MustCompile(`Redirecting...`)
is_redirected := ( len( reg.FindSubmatch(body) ) > 0 );

if is_redirected {
return SetRCPC(client, body, URL)
}
return body, err
}

// PostBody read post body
Expand Down