Skip to content

Commit

Permalink
fix: 修复 CRC 校验工具非空格隔开数据输入处理
Browse files Browse the repository at this point in the history
feat: CRC 校验工具 shareable
  • Loading branch information
HoshinoSuzumi committed Jun 12, 2023
1 parent e12fd98 commit 6a64e3b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nuxt.config.js
Expand Up @@ -162,7 +162,7 @@ export default {
},
manifest: {
lang: "zh",
id: "com.uniiem.ctfever",
id: "/?standalone=true",
name: "CTFever",
short_name: "CTFever",
description: "A fantastic toolkit for CTFers and everyone by uniiem.",
Expand Down
49 changes: 44 additions & 5 deletions pages/tools/crc-checksum.vue
Expand Up @@ -14,8 +14,8 @@
</template>
</InteractiveDoubleColumns>
<InteractiveBlock class="flex justify-between">
<UniButton @click="checksum" icon="tabler:calculator">{{ $t('common.btn_calculate') }}</UniButton>
<UniButton type="reset" danger icon="tabler:trash">{{ $t('common.btn_reset') }}</UniButton>
<UniButton @click="checksum(true)" icon="tabler:calculator">{{ $t('common.btn_calculate') }}</UniButton>
<UniButton @click="handleClean" danger icon="tabler:trash">{{ $t('common.btn_clean') }}</UniButton>
</InteractiveBlock>
<InteractiveBlock class="space-y-2">
<UniInput id="outputHex" :label="$t('tool.crc.checksum_result') + '(Hex)'" v-model="output.hex" disable
Expand Down Expand Up @@ -81,11 +81,43 @@ export default {
]
}
},
mounted() {
this.$nextTick(() => {
if (this.$route.query.crc_mode) {
this.crc_mode = this.$route.query.crc_mode
}
if (this.$route.query.input_mode) {
this.input_mode = this.$route.query.input_mode
}
if (this.$route.query.input_data) {
this.input_data = this.$route.query.input_data
}
this.checksum()
})
},
methods: {
checksum() {
let data = this.input_data;
checksum(updateRoute = false) {
if (updateRoute) {
this.$router.replace({
query: {
crc_mode: this.crc_mode,
input_mode: this.input_mode,
input_data: this.input_data
}
})
}
let input_data = this.input_data;
let data = this.input_data
if (this.input_mode === 'hex') {
data = data.split(' ').map(item => parseInt(item, 16));
data = []
input_data = input_data.replaceAll(' ', '')
if (input_data.length % 2 !== 0) {
return this.$message.error('Hex 格式输入错误,请使用两个字符表示一个字节');
}
// 从 input_data 中每两个字符为一个元素插入 data 中
for (let i = 0; i < input_data.length; i += 2) {
data.push(parseInt(input_data.substr(i, 2), 16));
}
}
let result = 0;
switch (this.crc_mode) {
Expand Down Expand Up @@ -121,6 +153,13 @@ export default {
hex: result.toString(16).toUpperCase(),
bin: result.toString(2)
};
},
handleClean() {
this.input_data = '';
this.output = {
hex: '',
bin: ''
};
}
},
}
Expand Down
3 changes: 2 additions & 1 deletion store/index.js
Expand Up @@ -245,7 +245,8 @@ export const state = () => ({
title: 'tool.crc.title',
description: 'tool.crc.desc',
route: '/tools/crc-checksum',
tags: [tagCategories.check, tagCategories.hash]
tags: [tagCategories.check, tagCategories.hash],
shareable: true
},
// {
// title: 'tool.temperatureConversion.title',
Expand Down

1 comment on commit 6a64e3b

@vercel
Copy link

@vercel vercel bot commented on 6a64e3b Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.