├── .github └── workflows │ └── ci.yml ├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── README.zh_CN.md ├── base1000 ├── __main__.py └── base1000.pyi ├── pyproject.toml ├── src ├── decode.rs ├── encode.rs ├── lib.rs └── main.rs └── 千字文 ├── 1.txt ├── 2.txt ├── 3.txt ├── 4.txt └── 5.txt /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This file is autogenerated by maturin v1.8.3 2 | # To update, run 3 | # 4 | # maturin generate-ci github 5 | # 6 | name: CI 7 | 8 | on: 9 | push: 10 | branches: 11 | - main 12 | - master 13 | tags: 14 | - '*' 15 | pull_request: 16 | workflow_dispatch: 17 | 18 | permissions: 19 | contents: read 20 | 21 | jobs: 22 | linux: 23 | runs-on: ${{ matrix.platform.runner }} 24 | strategy: 25 | matrix: 26 | platform: 27 | - runner: ubuntu-22.04 28 | target: x86_64 29 | - runner: ubuntu-22.04 30 | target: x86 31 | - runner: ubuntu-22.04 32 | target: aarch64 33 | - runner: ubuntu-22.04 34 | target: armv7 35 | - runner: ubuntu-22.04 36 | target: s390x 37 | - runner: ubuntu-22.04 38 | target: ppc64le 39 | steps: 40 | - uses: actions/checkout@v4 41 | - uses: actions/setup-python@v5 42 | with: 43 | python-version: 3.x 44 | - name: Build wheels 45 | uses: PyO3/maturin-action@v1 46 | with: 47 | target: ${{ matrix.platform.target }} 48 | args: --release --out dist --find-interpreter 49 | sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} 50 | manylinux: auto 51 | - name: Upload wheels 52 | uses: actions/upload-artifact@v4 53 | with: 54 | name: wheels-linux-${{ matrix.platform.target }} 55 | path: dist 56 | 57 | musllinux: 58 | runs-on: ${{ matrix.platform.runner }} 59 | strategy: 60 | matrix: 61 | platform: 62 | - runner: ubuntu-22.04 63 | target: x86_64 64 | - runner: ubuntu-22.04 65 | target: x86 66 | - runner: ubuntu-22.04 67 | target: aarch64 68 | - runner: ubuntu-22.04 69 | target: armv7 70 | steps: 71 | - uses: actions/checkout@v4 72 | - uses: actions/setup-python@v5 73 | with: 74 | python-version: 3.x 75 | - name: Build wheels 76 | uses: PyO3/maturin-action@v1 77 | with: 78 | target: ${{ matrix.platform.target }} 79 | args: --release --out dist --find-interpreter 80 | sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} 81 | manylinux: musllinux_1_2 82 | - name: Upload wheels 83 | uses: actions/upload-artifact@v4 84 | with: 85 | name: wheels-musllinux-${{ matrix.platform.target }} 86 | path: dist 87 | 88 | windows: 89 | runs-on: ${{ matrix.platform.runner }} 90 | strategy: 91 | matrix: 92 | platform: 93 | - runner: windows-latest 94 | target: x64 95 | - runner: windows-latest 96 | target: x86 97 | steps: 98 | - uses: actions/checkout@v4 99 | - uses: actions/setup-python@v5 100 | with: 101 | python-version: 3.x 102 | architecture: ${{ matrix.platform.target }} 103 | - name: Build wheels 104 | uses: PyO3/maturin-action@v1 105 | with: 106 | target: ${{ matrix.platform.target }} 107 | args: --release --out dist --find-interpreter 108 | sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} 109 | - name: Upload wheels 110 | uses: actions/upload-artifact@v4 111 | with: 112 | name: wheels-windows-${{ matrix.platform.target }} 113 | path: dist 114 | 115 | macos: 116 | runs-on: ${{ matrix.platform.runner }} 117 | strategy: 118 | matrix: 119 | platform: 120 | - runner: macos-13 121 | target: x86_64 122 | - runner: macos-14 123 | target: aarch64 124 | steps: 125 | - uses: actions/checkout@v4 126 | - uses: actions/setup-python@v5 127 | with: 128 | python-version: 3.x 129 | - name: Build wheels 130 | uses: PyO3/maturin-action@v1 131 | with: 132 | target: ${{ matrix.platform.target }} 133 | args: --release --out dist --find-interpreter 134 | sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} 135 | - name: Upload wheels 136 | uses: actions/upload-artifact@v4 137 | with: 138 | name: wheels-macos-${{ matrix.platform.target }} 139 | path: dist 140 | 141 | sdist: 142 | runs-on: ubuntu-latest 143 | steps: 144 | - uses: actions/checkout@v4 145 | - name: Build sdist 146 | uses: PyO3/maturin-action@v1 147 | with: 148 | command: sdist 149 | args: --out dist 150 | - name: Upload sdist 151 | uses: actions/upload-artifact@v4 152 | with: 153 | name: wheels-sdist 154 | path: dist 155 | 156 | release: 157 | name: Release 158 | runs-on: ubuntu-latest 159 | if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} 160 | needs: [linux, musllinux, windows, macos, sdist] 161 | permissions: 162 | # Use to sign the release artifacts 163 | id-token: write 164 | # Used to upload release artifacts 165 | contents: write 166 | # Used to generate artifact attestation 167 | attestations: write 168 | steps: 169 | - uses: actions/download-artifact@v4 170 | - name: Generate artifact attestation 171 | uses: actions/attest-build-provenance@v2 172 | with: 173 | subject-path: 'wheels-*/*' 174 | - name: Publish to PyPI 175 | if: ${{ startsWith(github.ref, 'refs/tags/') }} 176 | uses: PyO3/maturin-action@v1 177 | env: 178 | MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} 179 | with: 180 | command: upload 181 | args: --non-interactive --skip-existing wheels-*/* 182 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,vim,rust,python,venv 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,vim,rust,python,venv 3 | 4 | ### Linux ### 5 | *~ 6 | 7 | # temporary files which can be created if a process still has a handle open of a deleted file 8 | .fuse_hidden* 9 | 10 | # KDE directory preferences 11 | .directory 12 | 13 | # Linux trash folder which might appear on any partition or disk 14 | .Trash-* 15 | 16 | # .nfs files are created when an open file is removed but is still being accessed 17 | .nfs* 18 | 19 | ### macOS ### 20 | # General 21 | .DS_Store 22 | .AppleDouble 23 | .LSOverride 24 | 25 | # Icon must end with two \r 26 | Icon 27 | 28 | # Thumbnails 29 | ._* 30 | 31 | # Files that might appear in the root of a volume 32 | .DocumentRevisions-V100 33 | .fseventsd 34 | .Spotlight-V100 35 | .TemporaryItems 36 | .Trashes 37 | .VolumeIcon.icns 38 | .com.apple.timemachine.donotpresent 39 | 40 | # Directories potentially created on remote AFP share 41 | .AppleDB 42 | .AppleDesktop 43 | Network Trash Folder 44 | Temporary Items 45 | .apdisk 46 | 47 | ### macOS Patch ### 48 | # iCloud generated files 49 | *.icloud 50 | 51 | ### Python ### 52 | # Byte-compiled / optimized / DLL files 53 | __pycache__/ 54 | *.py[cod] 55 | *$py.class 56 | 57 | # C extensions 58 | *.so 59 | 60 | # Distribution / packaging 61 | .Python 62 | build/ 63 | develop-eggs/ 64 | dist/ 65 | downloads/ 66 | eggs/ 67 | .eggs/ 68 | lib/ 69 | lib64/ 70 | parts/ 71 | sdist/ 72 | var/ 73 | wheels/ 74 | share/python-wheels/ 75 | *.egg-info/ 76 | .installed.cfg 77 | *.egg 78 | MANIFEST 79 | 80 | # PyInstaller 81 | # Usually these files are written by a python script from a template 82 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 83 | *.manifest 84 | *.spec 85 | 86 | # Installer logs 87 | pip-log.txt 88 | pip-delete-this-directory.txt 89 | 90 | # Unit test / coverage reports 91 | htmlcov/ 92 | .tox/ 93 | .nox/ 94 | .coverage 95 | .coverage.* 96 | .cache 97 | nosetests.xml 98 | coverage.xml 99 | *.cover 100 | *.py,cover 101 | .hypothesis/ 102 | .pytest_cache/ 103 | cover/ 104 | 105 | # Translations 106 | *.mo 107 | *.pot 108 | 109 | # Django stuff: 110 | *.log 111 | local_settings.py 112 | db.sqlite3 113 | db.sqlite3-journal 114 | 115 | # Flask stuff: 116 | instance/ 117 | .webassets-cache 118 | 119 | # Scrapy stuff: 120 | .scrapy 121 | 122 | # Sphinx documentation 123 | docs/_build/ 124 | 125 | # PyBuilder 126 | .pybuilder/ 127 | target/ 128 | 129 | # Jupyter Notebook 130 | .ipynb_checkpoints 131 | 132 | # IPython 133 | profile_default/ 134 | ipython_config.py 135 | 136 | # pyenv 137 | # For a library or package, you might want to ignore these files since the code is 138 | # intended to run in multiple environments; otherwise, check them in: 139 | # .python-version 140 | 141 | # pipenv 142 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 143 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 144 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 145 | # install all needed dependencies. 146 | #Pipfile.lock 147 | 148 | # poetry 149 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 150 | # This is especially recommended for binary packages to ensure reproducibility, and is more 151 | # commonly ignored for libraries. 152 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 153 | #poetry.lock 154 | 155 | # pdm 156 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 157 | #pdm.lock 158 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 159 | # in version control. 160 | # https://pdm.fming.dev/#use-with-ide 161 | .pdm.toml 162 | 163 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 164 | __pypackages__/ 165 | 166 | # Celery stuff 167 | celerybeat-schedule 168 | celerybeat.pid 169 | 170 | # SageMath parsed files 171 | *.sage.py 172 | 173 | # Environments 174 | .env 175 | .venv 176 | env/ 177 | venv/ 178 | ENV/ 179 | env.bak/ 180 | venv.bak/ 181 | 182 | # Spyder project settings 183 | .spyderproject 184 | .spyproject 185 | 186 | # Rope project settings 187 | .ropeproject 188 | 189 | # mkdocs documentation 190 | /site 191 | 192 | # mypy 193 | .mypy_cache/ 194 | .dmypy.json 195 | dmypy.json 196 | 197 | # Pyre type checker 198 | .pyre/ 199 | 200 | # pytype static type analyzer 201 | .pytype/ 202 | 203 | # Cython debug symbols 204 | cython_debug/ 205 | 206 | # PyCharm 207 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 208 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 209 | # and can be added to the global gitignore or merged into this file. For a more nuclear 210 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 211 | #.idea/ 212 | 213 | ### Python Patch ### 214 | # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration 215 | poetry.toml 216 | 217 | # ruff 218 | .ruff_cache/ 219 | 220 | # LSP config files 221 | pyrightconfig.json 222 | 223 | ### Rust ### 224 | # Generated by Cargo 225 | # will have compiled files and executables 226 | debug/ 227 | 228 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 229 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 230 | Cargo.lock 231 | 232 | # These are backup files generated by rustfmt 233 | **/*.rs.bk 234 | 235 | # MSVC Windows builds of rustc generate these, which store debugging information 236 | *.pdb 237 | 238 | ### venv ### 239 | # Virtualenv 240 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ 241 | [Bb]in 242 | [Ii]nclude 243 | [Ll]ib 244 | [Ll]ib64 245 | [Ll]ocal 246 | [Ss]cripts 247 | pyvenv.cfg 248 | pip-selfcheck.json 249 | 250 | ### Vim ### 251 | # Swap 252 | [._]*.s[a-v][a-z] 253 | !*.svg # comment out if you don't need vector files 254 | [._]*.sw[a-p] 255 | [._]s[a-rt-v][a-z] 256 | [._]ss[a-gi-z] 257 | [._]sw[a-p] 258 | 259 | # Session 260 | Session.vim 261 | Sessionx.vim 262 | 263 | # Temporary 264 | .netrwhist 265 | # Auto-generated tag files 266 | tags 267 | # Persistent undo 268 | [._]*.un~ 269 | 270 | ### Windows ### 271 | # Windows thumbnail cache files 272 | Thumbs.db 273 | Thumbs.db:encryptable 274 | ehthumbs.db 275 | ehthumbs_vista.db 276 | 277 | # Dump file 278 | *.stackdump 279 | 280 | # Folder config file 281 | [Dd]esktop.ini 282 | 283 | # Recycle Bin used on file shares 284 | $RECYCLE.BIN/ 285 | 286 | # Windows Installer files 287 | *.cab 288 | *.msi 289 | *.msix 290 | *.msm 291 | *.msp 292 | 293 | # Windows shortcuts 294 | *.lnk 295 | 296 | # End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,vim,rust,python,venv 297 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "base1000" 3 | version = "0.1.1" 4 | authors = ["Li Hua "] 5 | edition = "2024" 6 | description = 'A text encoder based on the "Thousand Character Classic"' 7 | documentation = "https://docs.rs/base1000" 8 | readme = "README.md" 9 | repository = "https://github.com/real-LiHua/Base1000QianZiWenCodec" 10 | license = "Apache-2.0" 11 | keywords = ["base1000"] 12 | categories = ["command-line-utilities", "encoding"] 13 | include = ["/src/*.rs", "/千字文/*.txt"] 14 | 15 | [lib] 16 | name = "base1000" 17 | crate-type = ["cdylib", "rlib"] 18 | 19 | [dependencies] 20 | cfg-if = "1.0.0" 21 | clap = { version = "4.5.31", features = ["derive"], optional = true } 22 | itertools = "0.14.0" 23 | num-bigint = "0.4.6" 24 | pyo3 = { version="0.24.0", optional = true } 25 | rand = "0.9.0" 26 | rust-embed = { version = "8.6.0", features = ["debug-embed", "include-exclude"] } 27 | 28 | [features] 29 | encode = [] 30 | decode = [] 31 | default = ["clap", "encode", "decode"] 32 | 33 | [[bin]] 34 | name = "base1000" 35 | required-features = ["clap"] 36 | 37 | [profile.release] 38 | lto = true 39 | strip = "symbols" 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Base1000 Thousand Character Classic Encoder 2 | 3 | Base1000 is a text encoder based on the "Thousand Character Classic", supporting encoding any text into a sequence of "Thousand Character Classic" characters and decoding it back to the original text. 4 | 5 | [![Static Badge](https://img.shields.io/badge/DeepWiki-blue)](https://deepwiki.com/real-LiHua/Base1000QianZiWenCodec) 6 | 7 | 8 | ## Features 9 | 10 | - **Encoding**: Encode input text into a sequence of "Thousand Character Classic" characters. 11 | - **Decoding**: Decode a sequence of "Thousand Character Classic" characters back to the original text. 12 | - **Python Extension Module**: Provides a Python interface for direct usage in Python. 13 | - **Command Line Tool**: Offers a simple and easy-to-use CLI tool. 14 | 15 | ## Installation 16 | 17 | ### Build with Cargo 18 | Default enabled features (`clap`, `encode`, `decode`) 19 | 20 | ```bash 21 | cargo build --release 22 | ``` 23 | 24 | #### Enable Features 25 | 26 | - **`clap`**: Enables command-line tool functionality. Enable it with the following command: 27 | ```bash 28 | cargo build --release --features clap 29 | ``` 30 | 31 | - **`pyo3`**: Enables building the Python extension module. Enable it with the following command: 32 | ```bash 33 | cargo build --release --features pyo3 34 | ``` 35 | 36 | - **`encode`**: Enables text encoding functionality. Enable it with the following command: 37 | ```bash 38 | cargo build --release --features encode 39 | ``` 40 | 41 | - **`decode`**: Enables text decoding functionality. Enable it with the following command: 42 | ```bash 43 | cargo build --release --features decode 44 | ``` 45 | 46 | - Enable multiple features simultaneously: 47 | ```bash 48 | cargo build --release --features "clap pyo3 encode decode" 49 | ``` 50 | 51 | ### Build Python Extension with Maturin 52 | 53 | ```bash 54 | maturin build --release 55 | ``` 56 | 57 | ## Usage 58 | 59 | ### Command Line Tool 60 | 61 | #### Encoding 62 | 63 | ```bash 64 | base1000 -e "114514" 65 | ``` 66 | 67 | #### Decoding 68 | 69 | ```bash 70 | base1000 -d "夜裳移柰梧" 71 | ``` 72 | 73 | ### Python Extension 74 | 75 | #### Installation 76 | 77 | ```bash 78 | pip install . 79 | ``` 80 | 81 | #### Example 82 | 83 | ```python 84 | from base1000 import base1000 85 | 86 | # Encoding 87 | encoded = base1000.encode("114514") 88 | print(encoded) 89 | 90 | # Decoding 91 | for decoded in base1000.decode(encoded): 92 | print(decoded) 93 | ``` 94 | 95 | ## Testing 96 | 97 | Run unit tests: 98 | 99 | ```bash 100 | cargo test 101 | ``` 102 | 103 | ## Project Structure 104 | 105 | - `src/lib.rs`: Core library implementation. 106 | - `src/main.rs`: Command-line tool entry point. 107 | - `base1000/__main__.py`: Python CLI implementation. 108 | - `base1000/base1000.pyi`: Python type hint file. 109 | -------------------------------------------------------------------------------- /README.zh_CN.md: -------------------------------------------------------------------------------- 1 | # Base1000 千字文编码器 2 | 3 | Base1000 是一个基于《千字文》的文本编码器,支持将任意文本编码为《千字文》字符序列,并支持解码回原始文本。 4 | 5 | ## 功能 6 | 7 | - **编码**: 将输入文本编码为《千字文》字符序列。 8 | - **解码**: 将《千字文》字符序列解码回原始文本。 9 | - **Python 扩展模块**: 提供 Python 接口,支持直接在 Python 中调用。 10 | - **命令行工具**: 提供简单易用的 CLI 工具。 11 | 12 | ## 安装 13 | 14 | ### 使用 Cargo 构建 15 | 默认启用特性(clap、encode、decode) 16 | 17 | ```bash 18 | cargo build --release 19 | ``` 20 | 21 | #### 启用特性 22 | 23 | - **`clap`**: 启用后支持命令行工具功能。可以通过以下命令启用: 24 | ```bash 25 | cargo build --release --features clap 26 | ``` 27 | 28 | - **`pyo3`**: 启用后支持构建 Python 扩展模块。可以通过以下命令启用: 29 | ```bash 30 | cargo build --release --features pyo3 31 | ``` 32 | 33 | - **`encode`**: 启用后支持文本编码功能。可以通过以下命令启用: 34 | ```bash 35 | cargo build --release --features encode 36 | ``` 37 | 38 | - **`decode`**: 启用后支持文本解码功能。可以通过以下命令启用: 39 | ```bash 40 | cargo build --release --features decode 41 | ``` 42 | 43 | - 同时启用多个特性: 44 | ```bash 45 | cargo build --release --features "clap pyo3 encode decode" 46 | ``` 47 | 48 | 49 | ### 使用 Maturin 构建 Python 扩展 50 | 51 | ```bash 52 | maturin build --release 53 | ``` 54 | 55 | ## 使用方法 56 | 57 | ### 命令行工具 58 | 59 | #### 编码 60 | 61 | ```bash 62 | base1000 -e "114514" 63 | ``` 64 | 65 | #### 解码 66 | 67 | ```bash 68 | base1000 -d "夜裳移柰梧" 69 | ``` 70 | 71 | ### Python 扩展 72 | 73 | #### 安装 74 | 75 | ```bash 76 | pip install . 77 | ``` 78 | 79 | #### 示例 80 | 81 | ```python 82 | from base1000 import base1000 83 | 84 | # 编码 85 | encoded = base1000.encode("114514") 86 | print(encoded) 87 | 88 | # 解码 89 | for decoded in base1000.decode(encoded): 90 | print(decoded) 91 | ``` 92 | 93 | ## 测试 94 | 95 | 运行单元测试: 96 | 97 | ```bash 98 | cargo test 99 | ``` 100 | 101 | ## 项目结构 102 | 103 | - `src/lib.rs`: 核心库实现。 104 | - `src/main.rs`: 命令行工具入口。 105 | - `base1000/__main__.py`: Python CLI 实现。 106 | - `base1000/base1000.pyi`: Python 类型提示文件。 107 | -------------------------------------------------------------------------------- /base1000/__main__.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | from base1000 import base1000 4 | 5 | parser = argparse.ArgumentParser() 6 | group = parser.add_mutually_exclusive_group() 7 | 8 | if 'encode' in base1000.__all__: 9 | group.add_argument("-e", "--encode", action="store_true", help="编码输入文本") 10 | 11 | if 'decode' in base1000.__all__: 12 | group.add_argument("-d", "--decode", action="store_true", help="解码输入文本") 13 | 14 | parser.add_argument("text", help="需要编码或解码的文本") 15 | args = parser.parse_args() 16 | 17 | if 'encode' in base1000.__all__ and args.encode: 18 | print(base1000.encode(args.text)) 19 | elif 'decode' in base1000.__all__: 20 | for res in base1000.decode(args.text): 21 | print(res) 22 | -------------------------------------------------------------------------------- /base1000/base1000.pyi: -------------------------------------------------------------------------------- 1 | from typing import Iterator 2 | 3 | __all__: list[str] 4 | 5 | def encode(text: str) -> str: ... 6 | def decode(text: str) -> Iterator[str]: ... 7 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["maturin>=1.8,<2.0"] 3 | build-backend = "maturin" 4 | 5 | [project] 6 | name = "base1000" 7 | requires-python = ">=3.9" 8 | classifiers = [ 9 | "Programming Language :: Rust", 10 | "Programming Language :: Python :: Implementation :: CPython", 11 | "Programming Language :: Python :: Implementation :: PyPy", 12 | ] 13 | dynamic = ["version"] 14 | 15 | [tool.maturin] 16 | features = ["pyo3/extension-module"] 17 | -------------------------------------------------------------------------------- /src/decode.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "decode")] 2 | use crate::QIAN_ZI_WEN; 3 | use itertools::Itertools; 4 | use num_bigint::BigInt; 5 | use std::string::String; 6 | 7 | /// Decodes the given text into an iterator of possible original strings. 8 | /// 9 | /// # Arguments 10 | /// * `text` - The encoded text to decode. 11 | /// 12 | /// # Returns 13 | /// An iterator over possible decoded strings. 14 | /// 15 | /// # Features 16 | /// This function requires the `decode` feature to be enabled. 17 | /// 18 | /// # Examples 19 | /// ``` 20 | /// use base1000::decode; 21 | /// 22 | /// fn main() { 23 | /// for decoded in decode("夜裳移柰梧".to_string()) { 24 | /// println!("{}", decoded); 25 | /// } 26 | /// } 27 | /// ``` 28 | /// 29 | /// # Python Bindings 30 | /// This function is exposed to Python as `base1000.decode`. 31 | /// Requires the `pyo3` feature to be enabled for Python bindings. 32 | /// 33 | /// # Python Example 34 | /// ```python 35 | /// import base1000 36 | /// 37 | /// for decoded in base1000.decode("夜裳移柰梧"): 38 | /// print(decoded) 39 | /// ``` 40 | pub fn decode(text: String) -> impl Iterator { 41 | let character_indexes = &QIAN_ZI_WEN.1; 42 | return text 43 | .chars() 44 | .filter_map(|character| character_indexes.get(&character).cloned()) 45 | .multi_cartesian_product() 46 | .filter_map(|item| { 47 | BigInt::parse_bytes(item.join("").as_bytes(), 10) 48 | .and_then(|bigint| String::from_utf8(bigint.to_bytes_be().1).ok()) 49 | }); 50 | } 51 | 52 | #[cfg(test)] 53 | mod tests { 54 | use super::*; 55 | 56 | #[test] 57 | fn test_invalid_character_in_decode() { 58 | let invalid_text = String::from("InvalidCharacters"); 59 | let decoded: Vec = decode(invalid_text).collect(); 60 | assert!(decoded.is_empty()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/encode.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "encode")] 2 | use crate::QIAN_ZI_WEN; 3 | use num_bigint::BigInt; 4 | use num_bigint::Sign; 5 | use rand::prelude::Rng; 6 | use std::string::String; 7 | 8 | /// Encodes the given text into a string using the "Thousand Character Classic" character matrix. 9 | /// 10 | /// # Arguments 11 | /// * `text` - The input text to encode. 12 | /// 13 | /// # Returns 14 | /// A string representing the encoded text. 15 | /// 16 | /// # Features 17 | /// This function requires the `encode` feature to be enabled. 18 | /// 19 | /// # Examples 20 | /// ``` 21 | /// use base1000::encode; 22 | /// 23 | /// fn main() { 24 | /// let encoded = encode("114514".to_string()); 25 | /// println!("{}", encoded); 26 | /// } 27 | /// ``` 28 | /// 29 | /// # Python Bindings 30 | /// This function is exposed to Python as `base1000.encode`. 31 | /// Requires the `pyo3` feature to be enabled for Python bindings. 32 | /// 33 | /// # Python Example 34 | /// ```python 35 | /// import base1000 36 | /// 37 | /// encoded = base1000.encode("114514") 38 | /// print(encoded) 39 | /// ``` 40 | pub fn encode(text: String) -> String { 41 | let mut rng = rand::rng(); 42 | return encode_with_rng(text, &mut rng); 43 | } 44 | 45 | fn encode_with_rng(text: String, rng: &mut impl Rng) -> String { 46 | if text.is_empty() { 47 | return text; 48 | } 49 | let character_matrix = &*QIAN_ZI_WEN.0; 50 | let mut bigint_string: String = BigInt::from_bytes_be(Sign::Plus, text.as_bytes()).to_string(); 51 | bigint_string = "0".repeat((3 - bigint_string.len() % 3) % 3) + &bigint_string; 52 | return bigint_string 53 | .chars() 54 | .collect::>() 55 | .chunks(3) 56 | .map(|chunk| { 57 | let index = chunk.iter().collect::().parse::().unwrap(); 58 | character_matrix[index][rng.random_range(..character_matrix[index].len())] 59 | }) 60 | .collect(); 61 | } 62 | 63 | #[cfg(test)] 64 | mod tests { 65 | use super::*; 66 | 67 | use rand::prelude::*; 68 | 69 | #[test] 70 | fn test_encode() { 71 | let text = String::from("Hello, world!"); 72 | let encoded = encode(text.clone()); 73 | assert!(!encoded.is_empty()); 74 | assert_ne!(encoded, text); 75 | } 76 | 77 | #[test] 78 | fn test_encode_deterministic() { 79 | let text = String::from("114514"); 80 | let mut rng1 = StdRng::seed_from_u64(42); 81 | let mut rng2 = StdRng::seed_from_u64(42); 82 | let encoded1 = encode_with_rng(text.clone(), &mut rng1); 83 | let encoded2 = encode_with_rng(text.clone(), &mut rng2); 84 | assert_eq!(encoded1, encoded2); 85 | assert_eq!(encoded1, "夜裳移柰梧"); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! # Base1000 Thousand Character Classic Encoder 2 | //! 3 | //! Base1000 is a text encoder based on the "Thousand Character Classic", 4 | //! supporting encoding any text into a sequence of "Thousand Character Classic" characters 5 | //! and decoding it back to the original text. 6 | //! 7 | //! ## Features 8 | //! - `encode`: Enables text encoding functionality. 9 | //! - `decode`: Enables text decoding functionality. 10 | //! - `pyo3`: Enables Python bindings for encoding and decoding. 11 | use cfg_if::cfg_if; 12 | cfg_if! { 13 | if #[cfg(any(feature = "encode", feature = "decode"))] { 14 | use rust_embed::Embed; 15 | use std::collections::HashMap; 16 | use std::string::String; 17 | use std::sync::LazyLock; 18 | } 19 | } 20 | 21 | #[cfg(feature = "pyo3")] 22 | use pyo3::prelude::{Bound, PyModule, PyResult, pymodule}; 23 | 24 | #[cfg(all(feature = "pyo3", any(feature = "encode", feature = "decode")))] 25 | use pyo3::prelude::{PyModuleMethods, wrap_pyfunction}; 26 | 27 | #[cfg(all(feature = "pyo3", feature = "decode"))] 28 | use pyo3::prelude::{PyRef, PyRefMut, pyclass, pyfunction, pymethods}; 29 | 30 | #[cfg(all(feature = "pyo3", feature = "decode"))] 31 | use std::sync::{Arc, Mutex}; 32 | 33 | #[cfg(feature = "decode")] 34 | mod decode; 35 | #[cfg(feature = "encode")] 36 | mod encode; 37 | 38 | #[cfg(any(feature = "encode", feature = "decode"))] 39 | #[derive(Embed)] 40 | #[folder = "千字文"] 41 | #[include = "*.txt"] 42 | struct QianZiWenAssets; 43 | 44 | #[cfg(any(feature = "encode", feature = "decode"))] 45 | static QIAN_ZI_WEN: LazyLock<(Vec>, HashMap>)> = LazyLock::new(|| { 46 | #[cfg(feature = "encode")] 47 | let mut character_matrix = vec![Vec::new(); 1000]; 48 | #[cfg(not(feature = "encode"))] 49 | let character_matrix = vec![Vec::new(); 0]; 50 | 51 | #[cfg(feature = "decode")] 52 | let mut character_indexes: HashMap> = HashMap::new(); 53 | #[cfg(not(feature = "decode"))] 54 | let character_indexes: HashMap> = HashMap::new(); 55 | 56 | for file in QianZiWenAssets::iter() { 57 | for (index, character) in std::str::from_utf8(&QianZiWenAssets::get(&file).unwrap().data) 58 | .unwrap() 59 | .chars() 60 | .filter(|c| !c.is_whitespace()) 61 | .enumerate() 62 | { 63 | #[cfg(feature = "encode")] 64 | if !character_matrix[index].contains(&character) { 65 | character_matrix[index].push(character); 66 | } 67 | 68 | #[cfg(feature = "decode")] 69 | if !character_indexes.contains_key(&character) { 70 | character_indexes.insert(character, Vec::new()); 71 | } 72 | 73 | #[cfg(feature = "decode")] 74 | character_indexes.entry(character).and_modify(|x| { 75 | let temp_index = format!("{:03}", index); 76 | if !x.contains(&temp_index) { 77 | x.push(temp_index) 78 | } 79 | }); 80 | } 81 | } 82 | 83 | #[cfg(feature = "decode")] 84 | character_indexes.shrink_to_fit(); 85 | 86 | return (character_matrix, character_indexes); 87 | }); 88 | 89 | #[cfg(feature = "decode")] 90 | pub use crate::decode::decode; 91 | #[cfg(feature = "encode")] 92 | pub use crate::encode::encode; 93 | 94 | #[cfg(all(feature = "pyo3", feature = "encode"))] 95 | #[pyfunction(name = "encode")] 96 | fn py_encode(text: String) -> PyResult { 97 | Ok(encode(text)) 98 | } 99 | 100 | cfg_if! { 101 | if #[cfg(all(feature = "pyo3", feature = "decode"))] { 102 | #[pyclass] 103 | struct DecodeIterator { 104 | iter: Arc + Send>>>, 105 | } 106 | 107 | #[pymethods] 108 | impl DecodeIterator { 109 | fn __iter__(slf: PyRef<'_, Self>) -> PyRef<'_, Self> { 110 | slf 111 | } 112 | fn __next__(slf: PyRefMut<'_, Self>) -> Option { 113 | slf.iter.lock().unwrap().next() 114 | } 115 | } 116 | 117 | #[pyfunction(name = "decode")] 118 | fn py_decode(text: String) -> PyResult { 119 | Ok(DecodeIterator { 120 | iter: Arc::new(Mutex::new(Box::new(decode(text)))), 121 | }) 122 | } 123 | } 124 | } 125 | 126 | #[cfg(feature = "pyo3")] 127 | #[pymodule] 128 | fn base1000(m: &Bound<'_, PyModule>) -> PyResult<()> { 129 | #[cfg(feature = "encode")] 130 | m.add_function(wrap_pyfunction!(py_encode, m)?)?; 131 | #[cfg(feature = "decode")] 132 | m.add_function(wrap_pyfunction!(py_decode, m)?)?; 133 | Ok(()) 134 | } 135 | 136 | #[cfg(test)] 137 | mod tests { 138 | use super::*; 139 | 140 | #[cfg(any(feature = "encode", feature = "decode"))] 141 | #[test] 142 | fn test_qzw_initialization() { 143 | let qzw = &*QIAN_ZI_WEN.0; 144 | assert!(!qzw.is_empty()); 145 | assert_eq!(qzw.len(), 1000); 146 | } 147 | 148 | #[cfg(all(feature = "encode", feature = "decode"))] 149 | #[test] 150 | fn test_decode() { 151 | let text = String::from("Hello, world!"); 152 | let encoded = encode(text.clone()); 153 | let decoded: Vec = decode(encoded).collect(); 154 | assert!(decoded.contains(&text)); 155 | } 156 | 157 | #[cfg(all(feature = "encode", feature = "decode"))] 158 | #[test] 159 | fn test_empty_input() { 160 | let text = String::from(""); 161 | let encoded = encode(text.clone()); 162 | assert!(encoded.is_empty()); 163 | let decoded: Vec = decode(encoded).collect(); 164 | assert!(decoded.is_empty()); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "decode")] 2 | use base1000::decode; 3 | #[cfg(feature = "encode")] 4 | use base1000::encode; 5 | 6 | use clap::{Args, Parser}; 7 | 8 | #[derive(Parser)] 9 | #[command(version, about, long_about = None)] 10 | struct Cli { 11 | #[command(flatten)] 12 | opt: Opt, 13 | text: String, 14 | } 15 | 16 | #[derive(Args)] 17 | #[group(required = true, multiple = false)] 18 | struct Opt { 19 | #[cfg(feature = "encode")] 20 | #[arg(short, long)] 21 | encode: bool, 22 | 23 | #[cfg(feature = "decode")] 24 | #[arg(short, long)] 25 | decode: bool, 26 | } 27 | 28 | fn main() { 29 | let args = Cli::parse(); 30 | #[cfg(feature = "encode")] 31 | if args.opt.encode { 32 | let result: String = encode(args.text); 33 | println!("{}", result); 34 | return; 35 | } 36 | #[cfg(feature = "decode")] 37 | if args.opt.decode { 38 | for result in decode(args.text) { 39 | println!("{}", result); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /千字文/1.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /千字文/2.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /千字文/3.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /千字文/4.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /千字文/5.txt: -------------------------------------------------------------------------------- 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 | --------------------------------------------------------------------------------